### Eclipse Workspace Patch 1.0 #P org.jboss.tools.vpe Index: src/org/jboss/tools/vpe/editor/toolbar/format/FontNameFormatController.java =================================================================== --- src/org/jboss/tools/vpe/editor/toolbar/format/FontNameFormatController.java (revision 20277) +++ src/org/jboss/tools/vpe/editor/toolbar/format/FontNameFormatController.java (working copy) @@ -14,6 +14,7 @@ import org.jboss.tools.vpe.editor.template.textformating.FormatAttributeData; import org.jboss.tools.vpe.editor.toolbar.format.css.StyleAttribute; import org.jboss.tools.vpe.editor.toolbar.format.css.StyleProperty; +import org.jboss.tools.vpe.editor.toolbar.format.css.Token; import org.w3c.dom.Attr; /** @@ -80,33 +81,34 @@ * enabled) */ public void setToolbarItemEnabled(boolean enabled) { - comboBlockFormat.setEnabled(enabled); - if (enabled) { - Attr style = getStyleAttributeFromSelectedNode(true); - if (style != null) { - StyleAttribute styleAttribute = new StyleAttribute(style); - StyleProperty fontProperty = styleAttribute - .getProperty(STYLE_PROPERTY_NAME); - if (fontProperty != null) { - String fontName = fontProperty.getPropertyValue() - .getDirtyValue().trim(); - if (fontName != null) { - fontName = fontName.replaceAll(REPLACE_VALUE, EMPTY); - if (getComboBlockFormat().getText().equalsIgnoreCase( - fontName)) { - return; - } - String[] items = this.getComboBlockFormat().getItems(); - for (int i = 0; i < items.length; i++) { - if (items[i].equalsIgnoreCase(fontName)) { - this.getComboBlockFormat().select(i); - return; - } - } + comboBlockFormat.setEnabled(enabled); + if (enabled) { + Attr style = getStyleAttributeFromSelectedNode(true); + if (style != null) { + StyleAttribute styleAttribute = new StyleAttribute(style); + StyleProperty fontProperty + = styleAttribute.getProperty(STYLE_PROPERTY_NAME); + if (fontProperty != null) { + Token fontPropertyValue = fontProperty.getPropertyValue(); + if (fontPropertyValue != null) { + String fontName + = fontPropertyValue.getDirtyValue().trim(); + fontName = fontName.replaceAll(REPLACE_VALUE, EMPTY); + if (getComboBlockFormat().getText().equalsIgnoreCase( + fontName)) { + return; + } + String[] items = this.getComboBlockFormat().getItems(); + for (int i = 0; i < items.length; i++) { + if (items[i].equalsIgnoreCase(fontName)) { + this.getComboBlockFormat().select(i); + return; + } + } + } + } } } - } - } - getComboBlockFormat().select(0); + getComboBlockFormat().select(0); } -} \ No newline at end of file +} #P org.jboss.tools.jsf.vpe.jsf.test Index: src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java =================================================================== --- src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java (revision 20277) +++ src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java (working copy) @@ -18,6 +18,7 @@ import org.jboss.tools.jsf.vpe.jsf.test.jbide.ChangeMessageBundleTest_JBIDE5818; import org.jboss.tools.jsf.vpe.jsf.test.jbide.ContextMenuDoubleInsertionTest_JBIDE3888; +import org.jboss.tools.jsf.vpe.jsf.test.jbide.EditFontFamilyTest_JBIDE5872; import org.jboss.tools.jsf.vpe.jsf.test.jbide.FacetProcessingTest; import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE1105Test; import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE1460Test; @@ -122,6 +123,7 @@ TestSuite suite = new TestSuite("Tests for Vpe Jsf components"); //$NON-NLS-1$ // $JUnit-BEGIN$ + suite.addTestSuite(EditFontFamilyTest_JBIDE5872.class); suite.addTestSuite(ChangeMessageBundleTest_JBIDE5818.class); suite.addTestSuite(TestForUsingComponentsLibrariesWithDefaultNamespace.class); suite.addTestSuite(EditingSPecialSymbolsVPE_JBIDE3810.class); Index: resources/jsfTest/WebContent/pages/JBIDE/5872/JBIDE-5872.html =================================================================== --- resources/jsfTest/WebContent/pages/JBIDE/5872/JBIDE-5872.html (revision 0) +++ resources/jsfTest/WebContent/pages/JBIDE/5872/JBIDE-5872.html (revision 0) @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file Index: src/org/jboss/tools/jsf/vpe/jsf/test/jbide/EditFontFamilyTest_JBIDE5872.java =================================================================== --- src/org/jboss/tools/jsf/vpe/jsf/test/jbide/EditFontFamilyTest_JBIDE5872.java (revision 0) +++ src/org/jboss/tools/jsf/vpe/jsf/test/jbide/EditFontFamilyTest_JBIDE5872.java (revision 0) @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007-2009 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.jsf.vpe.jsf.test.jbide; + +import org.eclipse.jface.text.TextViewer; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Point; +import org.eclipse.wst.sse.ui.StructuredTextEditor; +import org.jboss.tools.jsf.vpe.jsf.test.JsfAllTests; +import org.jboss.tools.vpe.editor.VpeController; +import org.jboss.tools.vpe.ui.test.TestUtil; +import org.jboss.tools.vpe.ui.test.VpeTest; + +/** + * Test for JBIDE-5872: VPE throws java.lang.NullPointerException, + * while editing font-family. + * + * @see JBIDE-5872 + * @author Yahor Radtsevich (yradtsevich) + */ +public class EditFontFamilyTest_JBIDE5872 extends VpeTest { + private static final Point EDIT_POSITION = new Point(3, 40); + private static final int SELECTION_LENGTH = 1; + private static final String TEST_PAGE_NAME = "JBIDE/5872/JBIDE-5872.html"; + + public EditFontFamilyTest_JBIDE5872(String name) { + super(name); + } + + /** + * Deletes quote after style attribute. This may lead to NPE. + * + * @see JBIDE-5872 + */ + public void testEditFontFamily() throws Throwable { + TestUtil.waitForJobs(); + setException(null); + + VpeController vpeController + = openInVpe(JsfAllTests.IMPORT_PROJECT_NAME, TEST_PAGE_NAME); + StructuredTextEditor sourceEditor = vpeController.getSourceEditor(); + TextViewer textViewer = sourceEditor.getTextViewer(); + StyledText textWidget = textViewer.getTextWidget(); + + int offset = getCaretOffset(textViewer, EDIT_POSITION); + textWidget.setSelectionRange(offset, SELECTION_LENGTH); + textWidget.insert(""); + TestUtil.waitForIdle(); + + ISelectionProvider selectionProvider = sourceEditor.getSelectionProvider(); + vpeController.selectionChanged(new SelectionChangedEvent( + selectionProvider, selectionProvider.getSelection())); + + if(getException() != null) { + throw new Exception(getException()); + } + } + + private static int getCaretOffset(TextViewer textViewer, Point position) { + return TestUtil.getLinePositionOffcet(textViewer, position.x, position.y); + } +}