[jbosstools-commits] JBoss Tools SVN: r22835 - in trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe: editor/menu and 2 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Wed Jun 16 10:12:55 EDT 2010
Author: dmaliarevich
Date: 2010-06-16 10:12:54 -0400 (Wed, 16 Jun 2010)
New Revision: 22835
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/menu/ExternalizeStringsContributionItem.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/ExternalizeStringsAction.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 , comments were added, plus some insignificant adjustments.
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-06-16 13:23:16 UTC (rev 22834)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/dialog/ExternalizeStringsWizardPage.java 2010-06-16 14:12:54 UTC (rev 22835)
@@ -122,10 +122,6 @@
rbComboStatus = new Status(IStatus.OK, VpePlugin.PLUGIN_ID, Constants.EMPTY);
}
- public ExternalizeStringsWizardPage(String pageName) {
- super(pageName);
- }
-
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
@@ -288,50 +284,60 @@
setControl(composite);
}
+ /**
+ * Initialize dialog's controls.
+ * Fill in appropriate text and make validation.
+ */
private void initializeTextFields() {
- if (bm == null){
- VpePlugin.getDefault().logWarning(
- VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_INITIALIZATION_ERROR);
- } else {
- ISelection sel = editor.getSelectionProvider().getSelection();
- if ((propsValue != null) && (propsKey != null)
- && isSelectionCorrect(sel)) {
- String text = Constants.EMPTY;
- String stringToUpdate = Constants.EMPTY;
- TextSelection textSelection = null;
- IStructuredSelection structuredSelection = (IStructuredSelection) sel;
- textSelection = (TextSelection) sel;
- text = textSelection.getText();
- Object selectedElement = structuredSelection.getFirstElement();
- /*
- * When selected text in empty
- * parse selected element and find a string to replace.
- */
- if ((text.trim().length() == 0)) {
- if (selectedElement instanceof org.w3c.dom.Text) {
- org.w3c.dom.Text textNode = (org.w3c.dom.Text) selectedElement;
- if (textNode.getNodeValue().trim().length() > 0) {
- stringToUpdate = textNode.getNodeValue();
- editor.getSelectionProvider().setSelection(new StructuredSelection(stringToUpdate));
- }
- } else if (selectedElement instanceof Attr) {
- Attr attrNode = (Attr) selectedElement;
- if (attrNode.getNodeValue().trim().length() > 0) {
- stringToUpdate = attrNode.getNodeValue();
- editor.getSelectionProvider().setSelection(new StructuredSelection(stringToUpdate));
- }
+ ISelection sel = editor.getSelectionProvider().getSelection();
+ if (isSelectionCorrect(sel)) {
+ String text = Constants.EMPTY;
+ String stringToUpdate = Constants.EMPTY;
+ TextSelection textSelection = null;
+ IStructuredSelection structuredSelection = (IStructuredSelection) sel;
+ textSelection = (TextSelection) sel;
+ text = textSelection.getText();
+ Object selectedElement = structuredSelection.getFirstElement();
+ /*
+ * When selected text in 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();
+ editor.getSelectionProvider().setSelection(new StructuredSelection(stringToUpdate));
}
- if ((stringToUpdate.trim().length() > 0)) {
- text = stringToUpdate;
+ } else if (selectedElement instanceof Attr) {
+ /*
+ * ..or an attribute's value
+ */
+ Attr attrNode = (Attr) selectedElement;
+ if (attrNode.getNodeValue().trim().length() > 0) {
+ stringToUpdate = attrNode.getNodeValue();
+ editor.getSelectionProvider().setSelection(new StructuredSelection(stringToUpdate));
}
}
- /*
- * Update text string field
- */
- propsValue.setText(text.trim());
- /*
- * Initialize bundle messages field
- */
+ if ((stringToUpdate.trim().length() > 0)) {
+ text = stringToUpdate;
+ }
+ }
+ /*
+ * Update text string field.
+ * Trim the text to remove line breaks and caret returns.
+ */
+ propsValue.setText(text.trim());
+ /*
+ * Initialize bundle messages field
+ */
+ if (bm == null) {
+ VpePlugin.getDefault().logWarning(
+ VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_RB_IS_MISSING);
+ } else {
BundleEntry[] bundles = bm.getBundles();
Set<String> uriSet = new HashSet<String>();
for (BundleEntry bundleEntry : bundles) {
@@ -340,27 +346,38 @@
rbCombo.add(bundleEntry.uri);
}
}
- /*
- * Update status message.
- */
- updateStatus();
- } else {
- VpePlugin.getDefault().logWarning(
- VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_INITIALIZATION_ERROR);
}
+ /*
+ * Update status message.
+ */
+ updateStatus();
+ } else {
+ VpePlugin.getDefault().logWarning(
+ VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_INITIALIZATION_ERROR);
}
}
- private boolean isSelectionCorrect(ISelection sel) {
- if ((sel instanceof TextSelection)
- && (sel instanceof IStructuredSelection)
- && (((IStructuredSelection) sel).size() == 1)) {
+ /**
+ * 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;
- } else {
- return false;
- }
+ }
+ return false;
}
+ /**
+ * Checks keys in the selected resource bundle.
+ *
+ * @param key the key name
+ * @return <code>true</code> if there is a key with the specified name
+ */
private boolean isDuplicatedKey(String key) {
boolean isDupliacted = false;
if ((tagsTable.getItemCount() > 0) && (null != key) && !isNewFile()) {
@@ -375,11 +392,17 @@
return isDupliacted;
}
+ /**
+ * Update resource bundle table according to the selected file:
+ * it fills key and value columns.
+ *
+ * @param file the resource bundle file
+ */
private void updateTable(IFile file) {
if ((file != null) && file.exists()) {
try {
/*
- * Rad file content
+ * Read the file content
*/
BufferedReader in = new BufferedReader(new InputStreamReader(
file.getContents()));
@@ -405,6 +428,8 @@
}
line = in.readLine();
}
+ in.close();
+ in = null;
} catch (CoreException e) {
VpePlugin.getDefault().logError(
"Could not load file content for '" + file + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
@@ -418,6 +443,11 @@
}
}
+ /**
+ * Enables or disables resource bundle information
+ *
+ * @param enabled shows the status
+ */
private void enableBundleGroup(boolean enabled) {
propsFilesGroup.setEnabled(enabled);
propsFileLabel.setEnabled(enabled);
@@ -427,19 +457,36 @@
tagsTable.setEnabled(enabled);
}
+ /**
+ * Gets <code>key=value</code> pair
+ *
+ * @return a pair <code>\nkey=value\n</code>
+ */
public String getKeyValuePair() {
return "\n" + propsKey.getText() + Constants.EQUAL + propsValue.getText() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
}
+ /**
+ * Gets resource bundle's file
+ * @return the file
+ */
public IFile getBundleFile() {
return bm.getBundleFile(rbCombo.getText());
}
+ /**
+ * Check if "Create new file.." option is enabled
+ *
+ * @return the status
+ */
public boolean isNewFile() {
return newFile.getSelection();
}
- public boolean replaceText() {
+ /**
+ * Replaces the text in the current file
+ */
+ public void replaceText() {
IDocumentProvider prov = editor.getDocumentProvider();
IDocument doc = prov.getDocument(editor.getEditorInput());
ISelection sel = editor.getSelectionProvider().getSelection();
@@ -453,6 +500,11 @@
Object firstElement = structuredSelection.getFirstElement();
int offset = 0;
int length = 0;
+ /*
+ * When user selection is empty
+ * underlying node will e automatically selected.
+ * Thus we need to correct replacement offsets.
+ */
if ((textSel.getLength() != 0)) {
offset = textSel.getOffset();
length = textSel.getLength();
@@ -485,9 +537,11 @@
ex.printStackTrace();
}
}
- return true;
}
+ /**
+ * Update duplicate key status.
+ */
private void updateDuplicateKeyStatus() {
if (isDuplicatedKey(propsKey.getText())) {
rbComboStatus = new Status(
@@ -514,6 +568,9 @@
}
}
+ /**
+ * Update properties key status.
+ */
private void updatePropertiesKeyStatus() {
if ((propsKey.getText() == null)
|| (Constants.EMPTY.equalsIgnoreCase(propsKey.getText().trim()))) {
@@ -526,6 +583,9 @@
}
}
+ /**
+ * Update page status.
+ */
private void updateStatus() {
/*
* Update all statuses
@@ -543,6 +603,12 @@
setPageComplete(isPageComplete());
}
+ /**
+ * Apply status to the dialog.
+ *
+ * @param page the page
+ * @param statuses all the statuses
+ */
private void applyStatus(DialogPage page, IStatus[] statuses) {
IStatus severeStatus = statuses[0];
for (IStatus status : statuses) {
@@ -599,6 +665,13 @@
&& (newFile.getSelection() == true);
}
+ /**
+ * Creates new bundle map if no one was specified
+ * during initialization of the page.
+ *
+ * @param editor the source editor
+ * @return the new bundle map
+ */
private BundleMap createBundleMap(StructuredTextEditor editor) {
String uri = null;
String prefix = null;
@@ -624,7 +697,6 @@
} catch (CoreException e) {
VpePlugin.getPluginLog().logError(e);
}
-
/*
* Get Bundles from faces-config.xml
*/
@@ -651,7 +723,6 @@
}
}
}
-
/*
* Add bundles from <f:loadBundle> tags
*/
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/ExternalizeStringsContributionItem.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/ExternalizeStringsContributionItem.java 2010-06-16 13:23:16 UTC (rev 22834)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/ExternalizeStringsContributionItem.java 2010-06-16 14:12:54 UTC (rev 22835)
@@ -17,12 +17,20 @@
public class ExternalizeStringsContributionItem extends ActionContributionItem {
+ /**
+ * Instantiates a new externalize strings contribution item.
+ * Default constructor is used to create
+ * source editor context menu from plugin.xml
+ */
public ExternalizeStringsContributionItem() {
super(new ExternalizeStringsAction());
}
@Override
public void fill(Menu parent, int index) {
+ /*
+ * Simply sets the title
+ */
getAction().setText(VpeUIMessages.EXTERNALIZE_STRINGS);
super.fill(parent, index);
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/ExternalizeStringsAction.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/ExternalizeStringsAction.java 2010-06-16 13:23:16 UTC (rev 22834)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/ExternalizeStringsAction.java 2010-06-16 14:12:54 UTC (rev 22835)
@@ -38,6 +38,9 @@
if ((sel instanceof TextSelection)
&& (sel instanceof IStructuredSelection)
&& (((IStructuredSelection) sel).size() == 1)) {
+ /*
+ * Pass null for Bundle Map that it will be created by the page itself.
+ */
ExternalizeStringsDialog dlg = new ExternalizeStringsDialog(
PlatformUI.getWorkbench().getDisplay().getActiveShell(),
new ExternalizeStringsWizard(editor.getSourceEditor(), null));
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-06-16 13:23:16 UTC (rev 22834)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-06-16 14:12:54 UTC (rev 22835)
@@ -168,6 +168,7 @@
public static String EXTERNALIZE_STRINGS_DIALOG_PROPS_STRINGS_GROUP;
public static String EXTERNALIZE_STRINGS_DIALOG_PROPS_FILES_GROUP;
public static String EXTERNALIZE_STRINGS_DIALOG_INITIALIZATION_ERROR;
+ public static String EXTERNALIZE_STRINGS_DIALOG_RB_IS_MISSING;
public static String EXTERNALIZE_STRINGS_DIALOG_WRONG_SELECTION;
public static String EXTERNALIZE_STRINGS_DIALOG_WRONG_SELECTED_TEXT;
public static String EXTERNALIZE_STRINGS_DIALOG_PLEASE_SELECT_BUNDLE;
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-06-16 13:23:16 UTC (rev 22834)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-06-16 14:12:54 UTC (rev 22835)
@@ -156,6 +156,7 @@
EXTERNALIZE_STRINGS_DIALOG_PROPS_STRINGS_GROUP=Externalize strings
EXTERNALIZE_STRINGS_DIALOG_PROPS_FILES_GROUP=Handle properties file
EXTERNALIZE_STRINGS_DIALOG_INITIALIZATION_ERROR=Could not initialize externalization dialog!
+EXTERNALIZE_STRINGS_DIALOG_RB_IS_MISSING=Could not initialize resource bundles!
EXTERNALIZE_STRINGS_DIALOG_WRONG_SELECTION=Wrong selection! Please select correct string.
EXTERNALIZE_STRINGS_DIALOG_WRONG_SELECTED_TEXT=Wrong selected text. Please select correct string.
EXTERNALIZE_STRINGS_DIALOG_PLEASE_SELECT_BUNDLE=- Please select bundle -
More information about the jbosstools-commits
mailing list