[jbosstools-commits] JBoss Tools SVN: r39611 - in trunk: jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n and 5 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Mon Mar 19 08:27:49 EDT 2012
Author: dmaliarevich
Date: 2012-03-19 08:27:48 -0400 (Mon, 19 Mar 2012)
New Revision: 39611
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/resources/org/jboss/tools/vpe/editor/mozilla/icons/externalize.png
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VPEPropertyTester.java
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VPEPropertyTester.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/i18n/ExternalizeStringsUtils.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18nHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
Log:
https://issues.jboss.org/browse/JBIDE-11302 - i18n icon was added to the VPE toolbar.
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2012-03-19 12:26:45 UTC (rev 39610)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2012-03-19 12:27:48 UTC (rev 39611)
@@ -323,34 +323,6 @@
</visibleWhen>
</command>
</menuContribution>
- <menuContribution
- locationURI="toolbar:org.eclipse.ui.workbench.navigate?after=forwardHistory">
- <command
- commandId="org.jboss.tools.jst.jsp.commands.showSelectionBar"
- icon="icons/selbar.gif"
- id="org.jboss.tools.jst.jsp.toolbars.showSelectionBar"
- style="toggle"
- tooltip="%Toggle.Selection.Bar">
- <visibleWhen
- checkEnabled="false">
- <with
- variable="activeEditorId">
- <or>
- <equals
- value="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor">
- </equals>
- <equals
- value="org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor">
- </equals>
- <equals
- value="org.jboss.tools.jst.jsp.jspeditor.DocBookEditor">
- </equals>
- </or>
- </with>
- </visibleWhen>
- </command>
- </menuContribution>
-
<menuContribution
locationURI="popup:org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor.source.EditorContext?after=org.jboss.tools.vpe.editor.menu.SetupTemplateContributionItem">
<dynamic
@@ -408,24 +380,20 @@
icon="icons/externalize.png"
id="org.jboss.tools.jst.jsp.toolbars.i18"
tooltip="%Externalize.Selected.Property">
- <visibleWhen
- checkEnabled="false">
- <with
- variable="activeEditorId">
- <or>
- <equals
- value="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor">
- </equals>
- <equals
- value="org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor">
- </equals>
- <equals
- value="org.jboss.tools.jst.jsp.jspeditor.DocBookEditor">
- </equals>
- </or>
- </with>
- </visibleWhen>
+ <visibleWhen checkEnabled="false">
+ <reference definitionId="org.jboss.tools.ui.vpe.editor"/>
+ </visibleWhen>
</command>
+ <command
+ commandId="org.jboss.tools.jst.jsp.commands.showSelectionBar"
+ icon="icons/selbar.gif"
+ id="org.jboss.tools.jst.jsp.toolbars.showSelectionBar"
+ style="toggle"
+ tooltip="%Toggle.Selection.Bar">
+ <visibleWhen checkEnabled="false">
+ <reference definitionId="org.jboss.tools.ui.vpe.editor"/>
+ </visibleWhen>
+ </command>
</toolbar>
</menuContribution>
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java 2012-03-19 12:26:45 UTC (rev 39610)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java 2012-03-19 12:27:48 UTC (rev 39611)
@@ -87,6 +87,7 @@
import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
import org.jboss.tools.jst.web.tld.TaglibData;
import org.jboss.tools.jst.web.tld.URIConstants;
+import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -136,6 +137,54 @@
}
/**
+ * Check if the current selected text could be externalized
+ *
+ * @param selection text selection
+ * @return true, if i18n is possible
+ */
+ public static boolean isExternalizeStringsCommandEnabled(ISelection selection) {
+ boolean enabled=false;
+ String stringToUpdate = ""; //$NON-NLS-1$
+ if (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;
+ }
+
+ /**
* Find faces config xml file using XModel.
*
* @param model
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18nHandler.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18nHandler.java 2012-03-19 12:26:45 UTC (rev 39610)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/handlers/I18nHandler.java 2012-03-19 12:27:48 UTC (rev 39611)
@@ -49,63 +49,13 @@
if(activeEditor instanceof ITextEditor){
ITextEditor txtEditor = (ITextEditor) activeEditor;
ISelection selection = txtEditor.getSelectionProvider().getSelection();
- enabled = getExternalizeStringsCommandEnabled(selection);
+ enabled = ExternalizeStringsUtils.isExternalizeStringsCommandEnabled(selection);
}
}
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
Added: trunk/vpe/plugins/org.jboss.tools.vpe/resources/org/jboss/tools/vpe/editor/mozilla/icons/externalize.png
===================================================================
(Binary files differ)
Property changes on: trunk/vpe/plugins/org.jboss.tools.vpe/resources/org/jboss/tools/vpe/editor/mozilla/icons/externalize.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2012-03-19 12:26:45 UTC (rev 39610)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2012-03-19 12:27:48 UTC (rev 39611)
@@ -431,6 +431,12 @@
sourceSelectionChanged(true);
refreshCommands();
/*
+ * Enable/disable "Externalize strings" toolbar icon
+ * after after initialization
+ */
+ visualEditor.updateExternalizeStringsToolbarIconState(
+ sourceEditor.getSelectionProvider().getSelection());
+ /*
* Reset the flag, to enable scroll synchronizing right after init
*/
selectionManager.setUpdateSelectionEventFlag(false);
@@ -1628,6 +1634,12 @@
return;
}
/*
+ * Enable/disable "Externalize strings" toolbar icon
+ * after selection has been changed
+ */
+ visualEditor.updateExternalizeStringsToolbarIconState(
+ sourceEditor.getSelectionProvider().getSelection());
+ /*
* Update Text Formatting Toolbar state
*/
if (editPart.getVisualMode() != VpeEditorPart.SOURCE_MODE) {
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2012-03-19 12:26:45 UTC (rev 39610)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2012-03-19 12:27:48 UTC (rev 39611)
@@ -33,6 +33,7 @@
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.browser.ProgressEvent;
@@ -62,6 +63,10 @@
import org.eclipse.ui.part.EditorPart;
import org.eclipse.ui.statushandlers.StatusAdapter;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
+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.jboss.tools.jst.jsp.messages.JstUIMessages;
import org.jboss.tools.jst.jsp.preferences.IVpePreferencesPage;
import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.VpeController;
@@ -123,7 +128,8 @@
public static final String ICON_TEXT_FORMATTING = "icons/text-formatting.gif"; //$NON-NLS-1$
public static final String ICON_BUNDLE_AS_EL= "icons/bundle-as-el.gif"; //$NON-NLS-1$
public static final String ICON_SCROLL_LOCK= "icons/scroll_lock.gif"; //$NON-NLS-1$
-
+ public static final String ICON_EXTERNALIZE_STRINGS= "icons/externalize.png"; //$NON-NLS-1$
+
private XulRunnerEditor xulRunnerEditor;
private nsIDOMElement contentArea;
private nsIDOMNode headNode;
@@ -150,6 +156,7 @@
private Action showTextFormattingAction;
private Action showBundleAsELAction;
private Action scrollLockAction;
+ private Action externalizeStringsAction;
static {
/*
@@ -449,27 +456,28 @@
/*
* Create EXTERNALIZE STRINGS tool bar item
*/
-// externalizeStringsAction = new Action(JstUIMessages.EXTERNALIZE_STRINGS,
-// IAction.AS_PUSH_BUTTON) {
-// @Override
-// public void run() {
-// /*
-// * Externalize strings action.
-// * Show a dialog to add properties key and value.
-// * When selection is correct show the dialog
-// * otherwise the toolbar icon will be disabled.
-// */
-// ExternalizeStringsDialog dlg = new ExternalizeStringsDialog(
-// PlatformUI.getWorkbench().getDisplay().getActiveShell(),
-// new ExternalizeStringsWizard(controller.getSourceEditor(),
-// controller.getPageContext().getBundle()));
-// dlg.open();
-// }
-// };
-// externalizeStringsAction.setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class,
-// ICON_EXTERNALIZE_STRINGS));
-// externalizeStringsAction.setToolTipText(JstUIMessages.EXTERNALIZE_STRINGS);
-// toolBarManager.add(externalizeStringsAction);
+ externalizeStringsAction = new Action(JstUIMessages.EXTERNALIZE_STRINGS,
+ IAction.AS_PUSH_BUTTON) {
+
+ @Override
+ public void run() {
+ /*
+ * Externalize strings action.
+ * Show a dialog to add properties key and value.
+ * When selection is correct show the dialog
+ * otherwise the toolbar icon will be disabled.
+ */
+ ExternalizeStringsDialog dlg = new ExternalizeStringsDialog(
+ PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+ new ExternalizeStringsWizard(controller.getSourceEditor(),
+ controller.getPageContext().getBundle()));
+ dlg.open();
+ }
+ };
+ externalizeStringsAction.setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class,
+ ICON_EXTERNALIZE_STRINGS));
+ externalizeStringsAction.setToolTipText(JstUIMessages.EXTERNALIZE_STRINGS);
+ toolBarManager.add(externalizeStringsAction);
updateToolbarItemsAccordingToPreferences();
toolBarManager.update(true);
@@ -487,7 +495,7 @@
showNonVisualTagsAction = null;
showTextFormattingAction = null;
showBundleAsELAction = null;
-// externalizeStringsAction = null;
+ externalizeStringsAction = null;
}
});
return verBar;
@@ -1029,6 +1037,20 @@
return dropDownMenu;
}
+ /**
+ * Update Externalize Strings toolbar icon state.
+ * <p>
+ * Enables the button when suitable text is selected.
+ * Disabled otherwise.
+ */
+ public void updateExternalizeStringsToolbarIconState(ISelection selection) {
+ if (ExternalizeStringsUtils.isExternalizeStringsCommandEnabled(selection)) {
+ externalizeStringsAction.setEnabled(true);
+ } else {
+ externalizeStringsAction.setEnabled(false);
+ }
+ }
+
public void updateToolbarItemsAccordingToPreferences() {
String prefsOrientation = JspEditorPlugin
.getDefault().getPreferenceStore().getString(
Deleted: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VPEPropertyTester.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VPEPropertyTester.java 2012-03-19 12:26:45 UTC (rev 39610)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VPEPropertyTester.java 2012-03-19 12:27:48 UTC (rev 39611)
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2010 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.vpe.editor.toolbar;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.preferences.IVpePreferencesPage;
-
-/**
- * @author mareshkau
- *
- */
-public class VPEPropertyTester extends PropertyTester{
-
- public boolean test(Object receiver, String property, Object[] args,
- Object expectedValue) {
- return !JspEditorPlugin.getDefault().getPreferenceStore()
- .getBoolean(IVpePreferencesPage.SHOW_VISUAL_TOOLBAR);
- }
-}
Added: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VPEPropertyTester.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VPEPropertyTester.java (rev 0)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VPEPropertyTester.java 2012-03-19 12:27:48 UTC (rev 39611)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.vpe.editor.toolbar;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.preferences.IVpePreferencesPage;
+
+/**
+ * @author mareshkau
+ *
+ */
+public class VPEPropertyTester extends PropertyTester{
+
+ public boolean test(Object receiver, String property, Object[] args,
+ Object expectedValue) {
+ return !JspEditorPlugin.getDefault().getPreferenceStore()
+ .getBoolean(IVpePreferencesPage.SHOW_VISUAL_TOOLBAR);
+ }
+}
More information about the jbosstools-commits
mailing list