Author: dmaliarevich
Date: 2009-12-23 10:01:49 -0500 (Wed, 23 Dec 2009)
New Revision: 19557
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/TemplatesPreferencePage.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.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/jira/browse/JBIDE-5470, dialog was updated, tag name validation was
added, page controls were updated.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/TemplatesPreferencePage.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/TemplatesPreferencePage.java 2009-12-23
14:59:36 UTC (rev 19556)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/TemplatesPreferencePage.java 2009-12-23
15:01:49 UTC (rev 19557)
@@ -18,8 +18,6 @@
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -33,9 +31,6 @@
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.jboss.tools.common.model.ui.action.CommandBar;
-import org.jboss.tools.common.model.ui.action.CommandBarListener;
-import org.jboss.tools.common.model.ui.objecteditor.XTable;
import org.jboss.tools.vpe.editor.template.VpeAnyData;
import org.jboss.tools.vpe.editor.template.VpeEditAnyDialog;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
@@ -50,7 +45,7 @@
VpeUIMessages.TemplatesTableProvider_URI,
VpeUIMessages.TemplatesTableProvider_Children};
private static final int[] COLUMNS_WIDTHS = new int[] {
- 50, 50, 90, 30
+ 50, 50, 90, 40
};
private Table tagsTable;
private Button addButton;
@@ -58,10 +53,9 @@
private Button removeButton;
private List<VpeAnyData> tagsList;
- protected boolean changed;
+ protected boolean tagListWasChanged;
public TemplatesPreferencePage() {
- setPreferenceStore(getPreferenceStore());
/*
* Initialize tags list from the file
*/
@@ -86,7 +80,7 @@
composite.setFont(parent.getFont());
/*
- * Create datatable with the list of unknown tags
+ * Create data-table with the list of unknown tags
*/
tagsTable = new Table(composite, SWT.FULL_SELECTION | SWT.H_SCROLL |
SWT.V_SCROLL | SWT.BORDER);
TableLayout layout = new TableLayout();
@@ -94,19 +88,6 @@
tagsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
tagsTable.setHeaderVisible(true);
tagsTable.setLinesVisible(true);
- tagsTable.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- super.widgetSelected(e);
- }
-
- });
/*
* Create columns in the table
@@ -126,16 +107,16 @@
/*
* Add buttons
*/
- addButton = new Button(composite, SWT.NONE);
- addButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
+ addButton = new Button(composite, SWT.BUTTON1);
+ addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
addButton.setText(VpeUIMessages.TemplatesPreferencePage_Add);
- editButton = new Button(composite, SWT.NONE);
- editButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
+ editButton = new Button(composite, SWT.BUTTON1);
+ editButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
editButton.setText(VpeUIMessages.TemplatesPreferencePage_Edit);
- removeButton = new Button(composite, SWT.NONE);
- removeButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
+ removeButton = new Button(composite, SWT.BUTTON1);
+ removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
removeButton.setText(VpeUIMessages.TemplatesPreferencePage_Remove);
/*
@@ -152,19 +133,26 @@
}
private void updateTagsTable() {
+ /*
+ * If widget is null or disposed - exit.
+ */
if(tagsTable == null || tagsTable.isDisposed()) {
return;
}
+ /*
+ * Remember selection index.
+ */
int selectionIndex = tagsTable.getSelectionIndex();
/*
* Clear all previously saved items.
*/
tagsTable.clearAll();
- TableItem tableItem = null;
+ tagsTable.update();
/*
* Recreate table items
*/
+ TableItem tableItem = null;
for (int i = 0; i < tagsList.size(); i++) {
if(tagsTable.getItemCount() > i) {
/*
@@ -179,7 +167,7 @@
}
/*
* Fill in columns.
- * Tags table has 5 columns with checkbox in the first column.
+ * Tags table has 4 columns.
*/
String[] itemColumnsData = new String[tagsTable.getColumnCount()];
for (int j = 0; j < itemColumnsData.length; j++) {
@@ -241,16 +229,6 @@
if(v.indexOf('\r') >= 0) v = v.replace('\r', ' ');
return v;
}
-
- public boolean performOk() {
- if(changed) {
- /*
- * Commit changes to the file
- */
- VpeTemplateManager.getInstance().setAnyTemplates(tagsList);
- }
- return true;
- }
public void handleEvent(Event event) {
Widget source = event.widget;
@@ -266,6 +244,7 @@
* Add new template to the list.
*/
tagsList.add(data);
+ tagListWasChanged = true;
}
} else if (source == editButton) {
/*
@@ -274,22 +253,51 @@
VpeAnyData data = (VpeAnyData) tagsList.get(tagsTable.getSelectionIndex());
VpeEditAnyDialog editDialog = new VpeEditAnyDialog(getShell(), data);
editDialog.open();
- if(data.isChanged()){
- changed = true;
+ if(data.isChanged()) {
+ tagListWasChanged = true;
}
} else if (source == removeButton) {
/*
* Handle remove event
*/
tagsList.remove(tagsTable.getSelectionIndex());
+ tagListWasChanged = true;
} else {
/*
* Handle default event
*/
}
/*
- * Update tags table with the new tempales.
+ * Update tags table with the new templates.
*/
updateTagsTable();
}
+
+ @Override
+ public boolean performOk() {
+ if(tagListWasChanged) {
+ /*
+ * Commit changes to the file
+ */
+ VpeTemplateManager.getInstance().setAnyTemplates(tagsList);
+ }
+ return true;
+ }
+
+ @Override
+ protected void performApply() {
+ performOk();
+ }
+
+ @Override
+ protected void performDefaults() {
+ /*
+ * Initialize tags list from the file again.
+ * Update visual table.
+ */
+ tagsList = VpeTemplateManager.getInstance().getAnyTemplates();
+ updateTagsTable();
+ }
+
+
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java 2009-12-23
14:59:36 UTC (rev 19556)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java 2009-12-23
15:01:49 UTC (rev 19557)
@@ -143,6 +143,7 @@
text = data.getName();
}
tagName.setText(text);
+ tagName.addModifyListener(templateVerifier);
/*
* Create Tag URI label
@@ -161,6 +162,7 @@
text = data.getUri();
}
tagUri.setText(text);
+ tagUri.addModifyListener(templateVerifier);
/*
* Create Tag for display label
@@ -193,6 +195,7 @@
*/
childrenCheckbox = new Button(composite, SWT.CHECK);
childrenCheckbox.setLayoutData(new GridData(SWT.LEFT, SWT.NONE, true, false, 2,
1));
+ childrenCheckbox.setSelection(data.isChildren());
/*
* Create value label
@@ -206,7 +209,11 @@
*/
txtValue = new Text(composite, SWT.BORDER);
txtValue.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1));
- txtValue.setText(data.getValue() != null ? data.getValue() : "");
//$NON-NLS-1$
+ text = Constants.EMPTY;
+ if ((data != null) && (data.getValue() != null)) {
+ text = data.getValue();
+ }
+ txtValue.setText(text);
txtValue.addModifyListener(templateVerifier);
/*
@@ -334,6 +341,26 @@
VpePlugin.getPluginLog().logError(e);
}
}
+
+ /**
+ * Validates tag name.
+ * <p>
+ * Prefix should exist.
+ * <p>
+ * Otherwise template won't be saved correctly to auto-templates.xml.
+ *
+ * @return message is validation failed, null otherwise.
+ */
+ private IMessageProvider validateTagName() {
+ Message message = null;
+ if (tagName.getText().indexOf(":") < 0) { //$NON-NLS-1$
+ message = new Message(
+ MessageFormat.format(VpeUIMessages.TAG_NAME_IS_NOT_VALID,
+ tagName.getText().trim()),
+ IMessageProvider.ERROR);
+ }
+ return message;
+ }
/**
* Validates {@link VpeEditAnyDialog#txtTagForDisplay} field.
@@ -387,8 +414,11 @@
IMessageProvider tagForDisplayMessage = validateTagForDisplay();
IMessageProvider valueMessage = validateValue();
+ IMessageProvider tagNameMessage = validateTagName();
- if (tagForDisplayMessage != null) {
+ if (tagNameMessage != null) {
+ message = tagNameMessage;
+ } else if (tagForDisplayMessage != null) {
message = tagForDisplayMessage;
} else if (valueMessage != null) {
message = valueMessage;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateData.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateData.java 2009-12-23
14:59:36 UTC (rev 19556)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateData.java 2009-12-23
15:01:49 UTC (rev 19557)
@@ -71,7 +71,7 @@
}
public String getPrefix() {
- if (name != null && name.indexOf(":") > 0) { //$NON-NLS-1$
+ if ((name != null) && (name.indexOf(":") > 0)) { //$NON-NLS-1$
return name.substring(0, name.indexOf(":")); //$NON-NLS-1$
}
return null;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2009-12-23
14:59:36 UTC (rev 19556)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2009-12-23
15:01:49 UTC (rev 19557)
@@ -788,7 +788,7 @@
VpeAnyData data = iter.next();
root.appendChild(createNewTagElement(document, data));
String prefix = data.getPrefix();
- if (prefix != null && prefix.length() > 0 &&
!prefixSet.contains(prefix)) {
+ if ((prefix != null) && (prefix.length() > 0) &&
!prefixSet.contains(prefix)) {
root = appendTaglib(prefixSet, document, root, data);
prefixSet.add(prefix);
}
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 2009-12-23
14:59:36 UTC (rev 19556)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2009-12-23
15:01:49 UTC (rev 19557)
@@ -45,6 +45,8 @@
public static String TAG_STYLE;
public static String CHILDREN;
public static String VALUE;
+ public static String TAG_NAME_IS_NOT_VALID;
+ public static String TAG_FOR_DISPLAY_IS_NOT_VALID;
public static String VALUE_IS_NOT_VALID;
public static String BACKGROUND_COLOR;
public static String ERROR_OF_TYPE_CONVERSION;
@@ -80,7 +82,6 @@
public static String HIDE_TOOLBAR;
public static String SHOW;
public static String HIDE;
- public static String TAG_FOR_DISPLAY_IS_NOT_VALID;
public static String MenuCreationHelper_Cut;
public static String MenuCreationHelper_Paste;
public static String MenuCreationHelper_Test;
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 2009-12-23
14:59:36 UTC (rev 19556)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2009-12-23
15:01:49 UTC (rev 19557)
@@ -1,4 +1,4 @@
-ATTRIBUTES_MENU_ITEM=<{0}> Attributes
+AATTRIBUTES_MENU_ITEM=<{0}> Attributes
SELECT_THIS_TAG_MENU_ITEM=Select This Tag
STRIP_TAG_MENU_ITEM=Strip Tag
PARENT_TAG_MENU_ITEM=Parent Tag ({0})
@@ -26,6 +26,8 @@
TAG_STYLE=Tag style:
CHILDREN=Allow tag children:
VALUE=Value:
+TAG_NAME_IS_NOT_VALID=Tag name is not valid ({0})
+TAG_FOR_DISPLAY_IS_NOT_VALID=Tag for display is not valid ({0}).
VALUE_IS_NOT_VALID=Value is not valid ({0}).
BACKGROUND_COLOR=Background Color
@@ -62,7 +64,6 @@
NON_VISUAL_TAGS=Non-visual tags
SHOW=Show
HIDE=Hide
-TAG_FOR_DISPLAY_IS_NOT_VALID=Tag for display is not valid ({0}).
MenuCreationHelper_Cut=Cut
MenuCreationHelper_Paste=Paste
MenuCreationHelper_Test=Test