Author: dmaliarevich
Date: 2010-10-05 14:30:44 -0400 (Tue, 05 Oct 2010)
New Revision: 25499
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
Log:
https://jira.jboss.org/browse/JBIDE-7222 , correcting dialog's behavior when several
tags have been selected at one time.
Added:
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
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java 2010-10-05
18:30:44 UTC (rev 25499)
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.w3c.dom.Element;
+
+/**
+ * The Utils class for externalize strings routine.
+ */
+public class ExternalizeStringsUtils {
+
+ /**
+ * Checks that the user has selected a correct string.
+ *
+ * @param selection the current selection
+ * @return <code>true</code> if correct
+ */
+ public static boolean isSelectionCorrect(ISelection selection) {
+ boolean isSelectionCorrect = false;
+ if ((selection instanceof TextSelection)
+ && (selection instanceof IStructuredSelection)
+ && (((IStructuredSelection) selection).size() == 1)) {
+ /*
+ * In general selection is correct now except one case:
+ */
+ isSelectionCorrect = true;
+ /*
+ * If the whole tag is selected -- check if it has children.
+ * The wizard could not find a proper string to externalize
+ * among several tags.
+ */
+ Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
+ if (selectedElement instanceof Element) {
+ Element element = (Element) selectedElement;
+ if (element.hasChildNodes()) {
+ isSelectionCorrect = false;
+ }
+ }
+ }
+ return isSelectionCorrect;
+ }
+
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java 2010-10-05
17:56:17 UTC (rev 25498)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java 2010-10-05
18:30:44 UTC (rev 25499)
@@ -111,8 +111,18 @@
private Status propsValueStatus;
private Status duplicateKeyStatus;
private Table tagsTable;
-
-
+
+ /**
+ * Creates the wizard page
+ *
+ * @param pageName
+ * the name of the page
+ * @param editor
+ * the source text editor
+ * @param bm
+ * bundle map, or <code>null</code> - then the bundle map will
be
+ * created and initialized manually
+ */
public ExternalizeStringsWizardPage(String pageName, ITextEditor editor, BundleMap bm)
{
/*
* Setting dialog Title, Description, Image.
@@ -261,7 +271,7 @@
*/
private void initializeFieldsAndAddLIsteners() {
ISelection sel = editor.getSelectionProvider().getSelection();
- if (isSelectionCorrect(sel)) {
+ if (ExternalizeStringsUtils.isSelectionCorrect(sel)) {
String text = Constants.EMPTY;
String stringToUpdate = Constants.EMPTY;
TextSelection textSelection = null;
@@ -419,21 +429,6 @@
}
/**
- * Checks user has selected a correct string.
- *
- * @param selection the current selection
- * @return <code>true</code> if correct
- */
- private boolean isSelectionCorrect(ISelection selection) {
- if ((selection instanceof TextSelection)
- && (selection instanceof IStructuredSelection)
- && (((IStructuredSelection) selection).size() == 1)) {
- return true;
- }
- return false;
- }
-
- /**
* Checks keys in the selected resource bundle.
*
* @param key the key name
@@ -549,7 +544,7 @@
IDocumentProvider prov = editor.getDocumentProvider();
IDocument doc = prov.getDocument(editor.getEditorInput());
ISelection sel = editor.getSelectionProvider().getSelection();
- if (isSelectionCorrect(sel)) {
+ if (ExternalizeStringsUtils.isSelectionCorrect(sel)) {
try {
/*
* Get source text and new text
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java 2010-10-05
17:56:17 UTC (rev 25498)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java 2010-10-05
18:30:44 UTC (rev 25499)
@@ -22,6 +22,7 @@
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.jst.jsp.i18n.ExternalizeStringsUtils;
import org.jboss.tools.vpe.VpeDebug;
import org.jboss.tools.vpe.editor.VpeEditorPart;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
@@ -91,7 +92,10 @@
*
https://jira.jboss.org/browse/JBIDE-7222
* Adding ExternalizeStrings dialog to the VPE context menu
*/
-// menuManager.add(new ExternalizeStringsContributionItem());
+// if (ExternalizeStringsUtils.isSelectionCorrect(
+// vpeMenuUtil.getSelection())) {
+// menuManager.add(new ExternalizeStringsContributionItem());
+// }
addSeparator();
if (topLevelMenu) {
addZoomActions();
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-10-05
17:56:17 UTC (rev 25498)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2010-10-05
18:30:44 UTC (rev 25499)
@@ -36,6 +36,7 @@
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
@@ -65,6 +66,7 @@
import org.eclipse.wst.sse.ui.StructuredTextEditor;
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;
@@ -101,6 +103,7 @@
import org.mozilla.interfaces.nsIHTMLObjectResizer;
import org.mozilla.interfaces.nsIPlaintextEditor;
import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
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$
@@ -1110,6 +1113,55 @@
// StructuredTextEditor editor = controller.getSourceEditor();
// ISelection sel = editor.getSelectionProvider().getSelection();
// String stringToUpdate = Constants.EMPTY;
+// if (ExternalizeStringsUtils.isSelectionCorrect(sel)) {
+// 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);
+// }
+// }
+// /**
+// * 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)) {