Author: yradtsevich
Date: 2010-11-01 12:26:23 -0400 (Mon, 01 Nov 2010)
New Revision: 26166
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18nHandler.java
Removed:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18Handler.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/handlers/SelectionBarHandler.java
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/SelectionBarTest.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/handlers/PageDesignOptionsHandler.java
Log:
https://jira.jboss.org/browse/JBIDE-7462: Replace overriding of isEnabled() by
setEnabled(Object) for VPE command handlers.
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2010-11-01 16:22:37 UTC (rev
26165)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2010-11-01 16:26:23 UTC (rev
26166)
@@ -528,7 +528,7 @@
commandId="org.jboss.tools.jst.jsp.commands.showSelectionBar">
</handler>
<handler
- class="org.jboss.tools.jst.jsp.i18n.handlers.I18Handler"
+ class="org.jboss.tools.jst.jsp.i18n.handlers.I18nHandler"
commandId="org.jboss.tools.jst.jsp.commands.i18">
</handler>
</extension>
Deleted:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18Handler.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18Handler.java 2010-11-01
16:22:37 UTC (rev 26165)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18Handler.java 2010-11-01
16:26:23 UTC (rev 26166)
@@ -1,128 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2010 Exadel, Inc. and 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
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.jst.jsp.i18n.handlers;
-
-import java.util.Map;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.HandlerEvent;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.commands.IElementUpdater;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.menus.UIElement;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.jboss.tools.jst.jsp.i18n.ExternalizeStringsDialog;
-import org.jboss.tools.jst.jsp.i18n.ExternalizeStringsUtils;
-import org.jboss.tools.jst.jsp.i18n.ExternalizeStringsWizard;
-import org.w3c.dom.Attr;
-
-/**
- * Externalization command handler
- * @author mareshkau
- *
- */
-public class I18Handler extends AbstractHandler implements IElementUpdater{
-
- /* (non-Javadoc)
- * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
- */
- @Override
- public boolean isEnabled() {
- IEditorPart activeEditor= PlatformUI
- .getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- if(activeEditor instanceof ITextEditor){
- ITextEditor txtEditor = (ITextEditor) activeEditor;
- ISelection selection = txtEditor.getSelectionProvider().getSelection();
- return getExternalizeStringsCommandEnabled(selection);
- }
- return false;
- }
- /**
- *
- */
-// public I18Handler() {
-// setBaseEnabled(true);
-// }
- /**
- * Calculates the state of ext command
- * @param selection
- * @return
- */
- private static boolean getExternalizeStringsCommandEnabled(ISelection selection) {
- boolean enabled=false;
- String stringToUpdate = ""; //$NON-NLS-1$
- if (ExternalizeStringsUtils.isSelectionCorrect(selection)) {
- String text = ""; //$NON-NLS-1$
- TextSelection textSelection = null;
- IStructuredSelection structuredSelection = (IStructuredSelection) selection;
- textSelection = (TextSelection) selection;
- text = textSelection.getText();
- Object selectedElement = structuredSelection.getFirstElement();
- /*
- * When selected text is empty parse selected element and find a
- * string to replace..
- */
- if ((text.trim().length() == 0)) {
- if (selectedElement instanceof org.w3c.dom.Text) {
- /*
- * ..it could be a plain text
- */
- org.w3c.dom.Text textNode = (org.w3c.dom.Text) selectedElement;
- if (textNode.getNodeValue().trim().length() > 0) {
- stringToUpdate = textNode.getNodeValue();
- }
- } else if (selectedElement instanceof Attr) {
- /*
- * ..or an attribute's value
- */
- Attr attrNode = (Attr) selectedElement;
- if (attrNode.getNodeValue().trim().length() > 0) {
- stringToUpdate = attrNode.getNodeValue();
- }
- }
- } else {
- stringToUpdate = text;
- }
- }
- if ((stringToUpdate.length() > 0)) {
- enabled=true;
- }
- return enabled;
- }
-
- /**
- * the command has been executed, so extract extract the needed information
- * from the application context.
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IEditorPart activeEditor = HandlerUtil.getActiveEditorChecked(event);
-
- if(activeEditor instanceof ITextEditor){
- ExternalizeStringsDialog dlg = new ExternalizeStringsDialog(
- PlatformUI.getWorkbench().getDisplay().getActiveShell(),
- new ExternalizeStringsWizard((ITextEditor)activeEditor,
- null));
- dlg.open();
- }
- return null;
- }
-
- public void updateElement(UIElement element, Map parameters) {
- fireHandlerChanged(new HandlerEvent(this, true, false));
- }
-}
Copied:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18nHandler.java
(from rev 26152,
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18Handler.java)
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18nHandler.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18nHandler.java 2010-11-01
16:26:23 UTC (rev 26166)
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 Exadel, Inc. and 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
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.jst.jsp.i18n.handlers;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.HandlerEvent;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.menus.UIElement;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.jst.jsp.i18n.ExternalizeStringsDialog;
+import org.jboss.tools.jst.jsp.i18n.ExternalizeStringsUtils;
+import org.jboss.tools.jst.jsp.i18n.ExternalizeStringsWizard;
+import org.w3c.dom.Attr;
+
+/**
+ * Internationalization command handler
+ * @author mareshkau
+ *
+ */
+public class I18nHandler extends AbstractHandler implements IElementUpdater {
+
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ IEditorPart activeEditor= PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ boolean enabled;
+ if(activeEditor instanceof ITextEditor){
+ ITextEditor txtEditor = (ITextEditor) activeEditor;
+ ISelection selection = txtEditor.getSelectionProvider().getSelection();
+ enabled = getExternalizeStringsCommandEnabled(selection);
+ } else {
+ enabled = false;
+ }
+
+ if (isEnabled() != enabled) {
+ setBaseEnabled(enabled);
+ }
+ }
+
+// public I18nHandler() {
+// setBaseEnabled(true);
+// }
+ /**
+ * Calculates the state of ext command
+ * @param selection
+ * @return
+ */
+ private static boolean getExternalizeStringsCommandEnabled(ISelection selection) {
+ boolean enabled=false;
+ String stringToUpdate = ""; //$NON-NLS-1$
+ if (ExternalizeStringsUtils.isSelectionCorrect(selection)) {
+ String text = ""; //$NON-NLS-1$
+ TextSelection textSelection = null;
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ textSelection = (TextSelection) selection;
+ text = textSelection.getText();
+ Object selectedElement = structuredSelection.getFirstElement();
+ /*
+ * When selected text is empty parse selected element and find a
+ * string to replace..
+ */
+ if ((text.trim().length() == 0)) {
+ if (selectedElement instanceof org.w3c.dom.Text) {
+ /*
+ * ..it could be a plain text
+ */
+ org.w3c.dom.Text textNode = (org.w3c.dom.Text) selectedElement;
+ if (textNode.getNodeValue().trim().length() > 0) {
+ stringToUpdate = textNode.getNodeValue();
+ }
+ } else if (selectedElement instanceof Attr) {
+ /*
+ * ..or an attribute's value
+ */
+ Attr attrNode = (Attr) selectedElement;
+ if (attrNode.getNodeValue().trim().length() > 0) {
+ stringToUpdate = attrNode.getNodeValue();
+ }
+ }
+ } else {
+ stringToUpdate = text;
+ }
+ }
+ if ((stringToUpdate.length() > 0)) {
+ enabled=true;
+ }
+ return enabled;
+ }
+
+ /**
+ * the command has been executed, so extract extract the needed information
+ * from the application context.
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IEditorPart activeEditor = HandlerUtil.getActiveEditorChecked(event);
+
+ if(activeEditor instanceof ITextEditor){
+ ExternalizeStringsDialog dlg = new ExternalizeStringsDialog(
+ PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+ new ExternalizeStringsWizard((ITextEditor)activeEditor,
+ null));
+ dlg.open();
+ }
+ return null;
+ }
+
+ public void updateElement(UIElement element, Map parameters) {
+ fireHandlerChanged(new HandlerEvent(this, true, false));
+ }
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/handlers/SelectionBarHandler.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/handlers/SelectionBarHandler.java 2010-11-01
16:22:37 UTC (rev 26165)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/selection/bar/handlers/SelectionBarHandler.java 2010-11-01
16:26:23 UTC (rev 26166)
@@ -50,7 +50,9 @@
}
}
- setBaseEnabled(enabled);
+ if (enabled != isEnabled()) {
+ setBaseEnabled(enabled);
+ }
}
/**
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/SelectionBarTest.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/SelectionBarTest.java 2010-11-01
16:22:37 UTC (rev 26165)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/SelectionBarTest.java 2010-11-01
16:26:23 UTC (rev 26166)
@@ -56,18 +56,15 @@
public void testSelectionBarCommandState() throws Throwable{
assertEquals("check command enabled command
status",false,toggleSelBarCommand.isEnabled()); //$NON-NLS-1$
IEditorPart editorPart =
WorkbenchUtils.openEditor(project.getName()+"/WebContent/pages/selectionBar.xhtml");
//$NON-NLS-1$
- if(editorPart instanceof JSPMultiPageEditor){
- JSPMultiPageEditor multiPageEditor = (JSPMultiPageEditor) editorPart;
- multiPageEditor.pageChange(0);
- assertEquals("check command enabled command
status",true,toggleSelBarCommand.isEnabled()&&(Boolean)toggleSelBarState.getValue());
//$NON-NLS-1$
- multiPageEditor.pageChange(multiPageEditor.getPreviewIndex());
- assertEquals("check command enabled command
status",false,toggleSelBarCommand.isEnabled()&&(Boolean)toggleSelBarState.getValue());
//$NON-NLS-1$
- multiPageEditor.pageChange(0);
- assertEquals("check command enabled command
status",true,toggleSelBarCommand.isEnabled()&&(Boolean)toggleSelBarState.getValue());
//$NON-NLS-1$
- TestUtil.closeAllEditors();
- assertEquals("check command enabled command
status",false,toggleSelBarCommand.isEnabled()&&(Boolean)toggleSelBarState.getValue());
//$NON-NLS-1$
- } else{
- fail("Should be opened JSPMultiPage Editor"); //$NON-NLS-1$
- }
+
+ assertTrue("Should be opened JSPMultiPage Editor", //$NON-NLS-1$
+ editorPart instanceof JSPMultiPageEditor);
+ JSPMultiPageEditor multiPageEditor = (JSPMultiPageEditor) editorPart;
+ multiPageEditor.pageChange(0);
+ assertEquals("check command enabled command
status",true,toggleSelBarCommand.isEnabled()&&(Boolean)toggleSelBarState.getValue());
//$NON-NLS-1$
+ multiPageEditor.pageChange(multiPageEditor.getPreviewIndex());
+ assertEquals("check command enabled command
status",false,toggleSelBarCommand.isEnabled()&&(Boolean)toggleSelBarState.getValue());
//$NON-NLS-1$
+ multiPageEditor.pageChange(0);
+ assertEquals("check command enabled command
status",true,toggleSelBarCommand.isEnabled()&&(Boolean)toggleSelBarState.getValue());
//$NON-NLS-1$
}
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/handlers/PageDesignOptionsHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/handlers/PageDesignOptionsHandler.java 2010-11-01
16:22:37 UTC (rev 26165)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/handlers/PageDesignOptionsHandler.java 2010-11-01
16:26:23 UTC (rev 26166)
@@ -67,7 +67,7 @@
}
@Override
- public boolean isEnabled() {
+ public void setEnabled(Object evaluationContext) {
IEditorPart activeEditor = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IEditorInput input = activeEditor.getEditorInput();
@@ -81,6 +81,10 @@
file = FileUtil.getFile(input, path.lastSegment());
}
}
- return ((file != null) && (file.exists()));
+
+ boolean enabled = file != null && file.exists();
+ if (isEnabled() != enabled) {
+ setBaseEnabled(enabled);
+ }
}
}