Author: dmaliarevich
Date: 2010-09-01 11:09:08 -0400 (Wed, 01 Sep 2010)
New Revision: 24612
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/dialog/ExternalizeStringsWizardPage.java
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/messages/VpeUIMessages.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
https://jira.jboss.org/browse/JBIDE-6287 , enable/disable the icon depending on the
selection.
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 2010-09-01
15:06:57 UTC (rev 24611)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2010-09-01
15:09:08 UTC (rev 24612)
@@ -2248,6 +2248,14 @@
return;
}
+ /*
+ * Enable/disable "Externalize strings" toolbar icon
+ */
+ updateExternalizeStringsToolbarIconState();
+
+ /*
+ * Update Text Formatting Toolbar state
+ */
if (editPart.getVisualMode() != VpeEditorPart.SOURCE_MODE) {
if (toolbarFormatControllerManager != null)
toolbarFormatControllerManager.selectionChanged();
@@ -2528,6 +2536,16 @@
visualEditor.updateShowSelectionBarItem(selectionBar.isVisible());
}
+ /**
+ * Update Externalize Strings toolbar icon state.
+ * <p>
+ * Enables the button when suitable text is selected.
+ * Disabled otherwise.
+ */
+ public void updateExternalizeStringsToolbarIconState() {
+ visualEditor.updateExternalizeStringsToolbarIconState();
+ }
+
public IZoomEventManager getZoomEventManager() {
return zoomEventManager;
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/dialog/ExternalizeStringsWizardPage.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/dialog/ExternalizeStringsWizardPage.java 2010-09-01
15:06:57 UTC (rev 24611)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/dialog/ExternalizeStringsWizardPage.java 2010-09-01
15:09:08 UTC (rev 24612)
@@ -166,11 +166,7 @@
propsKey = new Text(propsStringGroup, SWT.BORDER);
propsKey.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1));
propsKey.setText(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_DEFAULT_KEY);
- propsKey.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- updateStatus();
- }
- });
+
/*
* Create Properties Value label
*/
@@ -184,11 +180,6 @@
propsValue.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1));
propsValue.setText(Constants.EMPTY);
propsValue.setEditable(false);
- propsValue.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- updateStatus();
- }
- });
/*
* Create New File Checkbox
@@ -206,22 +197,6 @@
gd.heightHint = 300;
propsFilesGroup.setLayoutData(gd);
propsFilesGroup.setText(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPS_FILES_GROUP);
-
- /*
- * Add selection listener to New File button
- */
- newFile.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- boolean selected = ((Button)e.getSource()).getSelection();
- if (selected) {
- enableBundleGroup(false);
- } else {
- enableBundleGroup(true);
- }
- updateStatus();
- }
- });
/*
* Create Resource Bundles List label
@@ -234,14 +209,6 @@
*/
rbCombo = new Combo(propsFilesGroup, SWT.NONE);
rbCombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1));
- rbCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- setResourceBundlePath(rbCombo.getText());
- updateDuplicateKeyStatus();
- updateStatus();
- }
- });
/*
* Create Properties File label
@@ -279,7 +246,7 @@
/*
* Initialize all fields with real values.
*/
- initializeTextFields();
+ initializeFieldsAndAddLIsteners();
/*
* Wizard Page control should be initialized.
@@ -291,7 +258,7 @@
* Initialize dialog's controls.
* Fill in appropriate text and make validation.
*/
- private void initializeTextFields() {
+ private void initializeFieldsAndAddLIsteners() {
ISelection sel = editor.getSelectionProvider().getSelection();
if (isSelectionCorrect(sel)) {
String text = Constants.EMPTY;
@@ -302,7 +269,7 @@
text = textSelection.getText();
Object selectedElement = structuredSelection.getFirstElement();
/*
- * When selected text in empty
+ * When selected text is empty
* parse selected element and find a string to replace..
*/
if ((text.trim().length() == 0)) {
@@ -393,15 +360,52 @@
}
/*
* Set the new key text
- * Update the key status
*/
propsKey.setText(newKey);
updateDuplicateKeyStatus();
}
/*
- * Update status message.
+ *
https://jira.jboss.org/browse/JBIDE-6945
+ * Set the greeting message only.
+ * All the validation will take place in the fields' listeners
+ * after user enters some new values.
*/
- updateStatus();
+ setMessage(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_ENTER_KEY_NAME,
+ IMessageProvider.INFORMATION);
+
+ /*
+ * Add selection listeners to the fields
+ */
+ propsKey.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateStatus();
+ }
+ });
+ propsValue.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateStatus();
+ }
+ });
+ newFile.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ boolean selected = ((Button)e.getSource()).getSelection();
+ if (selected) {
+ enableBundleGroup(false);
+ } else {
+ enableBundleGroup(true);
+ }
+ updateStatus();
+ }
+ });
+ rbCombo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setResourceBundlePath(rbCombo.getText());
+ updateDuplicateKeyStatus();
+ updateStatus();
+ }
+ });
} else {
VpePlugin.getDefault().logWarning(
VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_INITIALIZATION_ERROR);
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 2010-09-01
15:06:57 UTC (rev 24611)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2010-09-01
15:09:08 UTC (rev 24612)
@@ -78,6 +78,7 @@
import org.jboss.tools.vpe.editor.toolbar.VpeToolBarManager;
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
import org.jboss.tools.vpe.editor.toolbar.format.TextFormattingToolBar;
+import org.jboss.tools.vpe.editor.util.Constants;
import org.jboss.tools.vpe.editor.util.DocTypeUtil;
import org.jboss.tools.vpe.editor.util.FileUtil;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -98,6 +99,7 @@
import org.mozilla.interfaces.nsIHTMLInlineTableEditor;
import org.mozilla.interfaces.nsIHTMLObjectResizer;
import org.mozilla.interfaces.nsIPlaintextEditor;
+import org.w3c.dom.Attr;
public class MozillaEditor extends EditorPart implements IReusableEditor {
protected static final File INIT_FILE = new
File(VpePlugin.getDefault().getResourcePath("ve"), "init.html");
//$NON-NLS-1$ //$NON-NLS-2$
@@ -474,29 +476,16 @@
@Override
public void run() {
/*
- * Externalize strings action .
+ * Externalize strings action.
* Show a dialog to add properties key and value.
* When selection is correct show the dialog
- * otherwise show warning message.
+ * otherwise the toolbar icon will be disabled.
*/
- StructuredTextEditor editor = controller.getSourceEditor();
- ISelection sel = editor.getSelectionProvider().getSelection();
-
- if ((sel instanceof TextSelection)
- && (sel instanceof IStructuredSelection)
- && (((IStructuredSelection) sel).size() == 1)) {
- ExternalizeStringsDialog dlg = new ExternalizeStringsDialog(
- PlatformUI.getWorkbench().getDisplay().getActiveShell(),
- new ExternalizeStringsWizard(
- editor, controller.getPageContext().getBundle()));
- dlg.open();
- } else {
- MessageDialog.openWarning(
- PlatformUI.getWorkbench().getDisplay().getActiveShell(),
- VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE,
- VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_WRONG_SELECTION);
- }
-
+ ExternalizeStringsDialog dlg = new ExternalizeStringsDialog(
+ PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+ new ExternalizeStringsWizard(controller.getSourceEditor(),
+ controller.getPageContext().getBundle()));
+ dlg.open();
}
};
externalizeStringsAction.setImageDescriptor(ImageDescriptor.createFromFile(MozillaEditor.class,
@@ -521,6 +510,7 @@
showSelectionBarAction = null;
showTextFormattingAction = null;
showBundleAsELAction = null;
+ externalizeStringsAction = null;
}
});
return verBar;
@@ -1139,4 +1129,57 @@
public MozillaTooltipListener getTooltipListener() {
return tooltipListener;
}
+
+
+ /**
+ * Update Externalize Strings toolbar icon state.
+ * <p>
+ * Enables the button when suitable text is selected.
+ * Disabled otherwise.
+ */
+ public void updateExternalizeStringsToolbarIconState() {
+ StructuredTextEditor editor = controller.getSourceEditor();
+ ISelection sel = editor.getSelectionProvider().getSelection();
+ String stringToUpdate = Constants.EMPTY;
+ if ((sel instanceof TextSelection)
+ && (sel instanceof IStructuredSelection)
+ && (((IStructuredSelection) sel).size() == 1)) {
+ String text = Constants.EMPTY;
+ TextSelection textSelection = null;
+ IStructuredSelection structuredSelection = (IStructuredSelection) sel;
+ textSelection = (TextSelection) sel;
+ 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)) {
+ externalizeStringsAction.setEnabled(true);
+ } else {
+ externalizeStringsAction.setEnabled(false);
+ }
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-09-01
15:06:57 UTC (rev 24611)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-09-01
15:09:08 UTC (rev 24612)
@@ -185,6 +185,8 @@
public static String EXTERNALIZE_STRINGS_DIALOG_PROPERTY_NAME;
public static String EXTERNALIZE_STRINGS_DIALOG_PROPERTY_VALUE;
public static String EXTERNALIZE_STRINGS_DIALOG_KEY_ALREADY_EXISTS;
+ public static String EXTERNALIZE_STRINGS_DIALOG_ENTER_KEY_NAME;
+ public static String EXTERNALIZE_STRINGS_DIALOG_SELECT_RESOURCE_BUNDLE;
public static String COULD_NOT_OPEN_VPE_RESOURCES_DIALOG;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-09-01
15:06:57 UTC (rev 24611)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-09-01
15:09:08 UTC (rev 24612)
@@ -150,11 +150,11 @@
LIST_IS_EMPTY=List is empty
# Externalize Strings Dialog
-EXTERNALIZE_STRINGS_DIALOG_TITLE=Externalize Strings Dialog
+EXTERNALIZE_STRINGS_DIALOG_TITLE=Externalize Strings
EXTERNALIZE_STRINGS_DIALOG_DESCRIPTION=Externalize your strings via properties file
EXTERNALIZE_STRINGS_DIALOG_TEXT_STRING=Text string:
-EXTERNALIZE_STRINGS_DIALOG_PROPERTIES_KEY=Properties key:
-EXTERNALIZE_STRINGS_DIALOG_PROPERTIES_VALUE=Properties value:
+EXTERNALIZE_STRINGS_DIALOG_PROPERTIES_KEY=Property key:
+EXTERNALIZE_STRINGS_DIALOG_PROPERTIES_VALUE=Property value:
EXTERNALIZE_STRINGS_DIALOG_PROPERTIES_FILE=Properties file:
EXTERNALIZE_STRINGS_DIALOG_RESOURCE_BUNDLE_LIST=Select resource bundle:
EXTERNALIZE_STRINGS_DIALOG_PROPS_STRINGS_GROUP=Externalize strings
@@ -173,6 +173,8 @@
EXTERNALIZE_STRINGS_DIALOG_PROPERTY_NAME=Property name
EXTERNALIZE_STRINGS_DIALOG_PROPERTY_VALUE=Property value
EXTERNALIZE_STRINGS_DIALOG_KEY_ALREADY_EXISTS=Such a key already exists
+EXTERNALIZE_STRINGS_DIALOG_ENTER_KEY_NAME=Please specify the property key
+EXTERNALIZE_STRINGS_DIALOG_SELECT_RESOURCE_BUNDLE=Please select the resource bundle
# Other messages
CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT=Cannot load taglibs from PageContext!