Author: dmaliarevich
Date: 2010-05-17 09:51:21 -0400 (Mon, 17 May 2010)
New Revision: 22119
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/VpeImportExportWizardPage.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/VpeImportExportWizardsUtils.java
Removed:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/wizard/
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/ExportUnknownTagsTemplatesWizardPage.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/ImportUnknownTagsTemplatesWizardPage.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
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeUiTests.java
Log:
Removing duplicate code from import/export wizards. JUnits were corrected.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/ExportUnknownTagsTemplatesWizardPage.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/ExportUnknownTagsTemplatesWizardPage.java 2010-05-17
13:10:52 UTC (rev 22118)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/ExportUnknownTagsTemplatesWizardPage.java 2010-05-17
13:51:21 UTC (rev 22119)
@@ -15,19 +15,11 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ColumnLayoutData;
import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableLayout;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
@@ -40,9 +32,7 @@
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.WizardExportResourcesPage;
import org.jboss.tools.vpe.editor.template.VpeAnyData;
@@ -56,17 +46,9 @@
*
* @author dmaliarevich
*/
-public class ExportUnknownTagsTemplatesWizardPage extends WizardExportResourcesPage {
+public class ExportUnknownTagsTemplatesWizardPage extends
+ WizardExportResourcesPage implements VpeImportExportWizardPage {
- private static final String[] COLUMNS_NAMES = new String[] {
- VpeUIMessages.TemplatesTableProvider_TagName,
- VpeUIMessages.TemplatesTableProvider_TagForDisplay,
- VpeUIMessages.TemplatesTableProvider_URI,
- VpeUIMessages.TemplatesTableProvider_Children};
- private static final int[] COLUMNS_WIDTHS = new int[] {
- 50, 50, 90, 40
- };
-
private String pathString;
private Table tagsTable;
private List<VpeAnyData> tagsList;
@@ -123,7 +105,7 @@
/*
* Fill the table with stored tags
*/
- updateTagsTable(true);
+ VpeImportExportWizardsUtils.updateTagsTable(tagsTable, tagsList, true);
/*
* Add path output and browse button
@@ -173,113 +155,6 @@
*/
}
- /**
- * Updates visual table with tags templates.
- *
- * @param clearTagsTable clears current tags table
- */
- private void updateTagsTable(boolean clearTagsTable) {
- /*
- * Return when visual table hasn't been initialized.
- */
- if(tagsTable == null || tagsTable.isDisposed()) {
- return;
- }
- /*
- * Clear current visual table.
- */
- if (clearTagsTable) {
- tagsTable.clearAll();
- }
- /*
- * Return when tags templates list hasn't been initialized.
- */
- if (tagsList == null) {
- return;
- }
- /*
- * Remember current selection index
- * and restore it at the end.
- */
- int selectionIndex = tagsTable.getSelectionIndex();
- TableItem tableItem = null;
- for (int i = 0; i < tagsList.size(); i++) {
- if(tagsTable.getItemCount() > i) {
- /*
- * Use existed items
- */
- tableItem = tagsTable.getItem(i);
- } else {
- /*
- * Add necessary item
- */
- tableItem = new TableItem(tagsTable, SWT.BORDER, i);
- }
- /*
- * Fill in columns.
- */
- String[] itemColumnsData = new String[tagsTable.getColumnCount()];
- for (int j = 0; j < itemColumnsData.length; j++) {
- /*
- * Getting values from tagList
- */
- itemColumnsData[j] = toVisualValue(getValueAt(i, j));
- }
- /*
- * Set cells text
- */
- tableItem.setText(itemColumnsData);
-
- }
-
- /*
- * Restoring selection index
- */
- if (selectionIndex > 0 ) {
- try {
- tagsTable.setSelection(selectionIndex);
- } catch (SWTException e) {
- /*
- * Do nothing
- */
- }
- }
- }
-
- public String getValueAt(int row, int column) {
- String result = "List is empty"; //$NON-NLS-1$
- if ((null != tagsList) && ((row >= 0) && (tagsList.size() > 0)
&& (row < tagsList.size()))) {
- VpeAnyData tagItem = (VpeAnyData)tagsList.get(row);
- switch(column){
- case 0:
- result = tagItem.getName();
- break;
- case 1:
- result = tagItem.getTagForDisplay();
- break;
- case 2:
- result = tagItem.getUri();
- break;
- case 3:
- if(tagItem.isChildren()) {
- result = VpeUIMessages.TemplatesTableProvider_Yes;
- } else {
- result = VpeUIMessages.TemplatesTableProvider_No;
- }
- break;
- }
- }
- return result;
- }
-
- private String toVisualValue(String v) {
- if(v == null) return ""; //$NON-NLS-1$
- if(v.indexOf('\n') >= 0) v = v.replace('\n', ' ');
- if(v.indexOf('\t') >= 0) v = v.replace('\t', ' ');
- if(v.indexOf('\r') >= 0) v = v.replace('\r', ' ');
- return v;
- }
-
public void handleEvent(Event event) {
/*
* Do nothing
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/ImportUnknownTagsTemplatesWizardPage.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/ImportUnknownTagsTemplatesWizardPage.java 2010-05-17
13:10:52 UTC (rev 22118)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/ImportUnknownTagsTemplatesWizardPage.java 2010-05-17
13:51:21 UTC (rev 22119)
@@ -22,7 +22,6 @@
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
@@ -31,13 +30,10 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.WizardResourceImportPage;
import org.jboss.tools.vpe.VpePlugin;
@@ -47,29 +43,18 @@
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.resref.core.ReferenceWizardPage;
-
/**
* Page for importing unknown tags templates.
*
* @author dmaliarevich
*/
public class ImportUnknownTagsTemplatesWizardPage extends
- WizardResourceImportPage {
-
- private static final String[] COLUMNS_NAMES = new String[] {
- VpeUIMessages.TemplatesTableProvider_TagName,
- VpeUIMessages.TemplatesTableProvider_TagForDisplay,
- VpeUIMessages.TemplatesTableProvider_URI,
- VpeUIMessages.TemplatesTableProvider_Children};
- private static final int[] COLUMNS_WIDTHS = new int[] {
- 50, 50, 90, 40
- };
+ WizardResourceImportPage implements VpeImportExportWizardPage {
private String pathString;
private Table tagsTable;
private List<VpeAnyData> tagsList;
-
/**
* Constructor
*
@@ -127,7 +112,7 @@
/*
* Update table tags list based on the loaded file.
*/
- updateTagsTable(true);
+ VpeImportExportWizardsUtils.updateTagsTable(tagsTable, tagsList, true);
/*
* Check if the page is complete.
*/
@@ -182,111 +167,7 @@
setControl(composite);
}
-
- /**
- * Updates visual table with tags templates.
- *
- * @param clearTagsTable clears current tags table
- */
- private void updateTagsTable(boolean clearTagsTable) {
- /*
- * Return when visual table hasn't been initialized.
- */
- if(tagsTable == null || tagsTable.isDisposed()) {
- return;
- }
- /*
- * Clear current visual table.
- */
- if (clearTagsTable) {
- tagsTable.clearAll();
- }
- /*
- * Return when tags templates list hasn't been initialized.
- */
- if (tagsList == null) {
- return;
- }
- /*
- * Remember current selection index
- * and restore it at the end.
- */
- int selectionIndex = tagsTable.getSelectionIndex();
- TableItem tableItem = null;
- for (int i = 0; i < tagsList.size(); i++) {
- if(tagsTable.getItemCount() > i) {
- /*
- * Use existed items
- */
- tableItem = tagsTable.getItem(i);
- } else {
- /*
- * Add new item
- */
- tableItem = new TableItem(tagsTable, SWT.BORDER, i);
- }
- /*
- * Fill in columns.
- */
- String[] itemColumnsData = new String[tagsTable.getColumnCount()];
- for (int j = 0; j < itemColumnsData.length; j++) {
- /*
- * Getting values from tagList
- */
- itemColumnsData[j] = toVisualValue(getValueAt(i, j));
- }
- /*
- * Set cells text
- */
- tableItem.setText(itemColumnsData);
- }
- /*
- * Restoring selection index
- */
- if (selectionIndex > 0 ) {
- try {
- tagsTable.setSelection(selectionIndex);
- } catch (SWTException e) {
- VpePlugin.getDefault().logError(
- VpeUIMessages.COULD_NOT_SET_TABLE_SELECTION, e);
- }
- }
- }
- public String getValueAt(int row, int column) {
- String result = "List is empty"; //$NON-NLS-1$
- if ((null != tagsList) && ((row >= 0) && (tagsList.size() > 0)
&& (row < tagsList.size()))) {
- VpeAnyData tagItem = (VpeAnyData)tagsList.get(row);
- switch(column){
- case 0:
- result = tagItem.getName();
- break;
- case 1:
- result = tagItem.getTagForDisplay();
- break;
- case 2:
- result = tagItem.getUri();
- break;
- case 3:
- if(tagItem.isChildren()) {
- result = VpeUIMessages.TemplatesTableProvider_Yes;
- } else {
- result = VpeUIMessages.TemplatesTableProvider_No;
- }
- break;
- }
- }
- return result;
- }
-
- private String toVisualValue(String v) {
- if(v == null) return ""; //$NON-NLS-1$
- if(v.indexOf('\n') >= 0) v = v.replace('\n', ' ');
- if(v.indexOf('\t') >= 0) v = v.replace('\t', ' ');
- if(v.indexOf('\r') >= 0) v = v.replace('\r', ' ');
- return v;
- }
-
@Override
public boolean isPageComplete() {
boolean isPageComplete = false;
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/VpeImportExportWizardPage.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/VpeImportExportWizardPage.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/VpeImportExportWizardPage.java 2010-05-17
13:51:21 UTC (rev 22119)
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.vpe.editor.wizards;
+
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+
+public interface VpeImportExportWizardPage {
+
+ String[] COLUMNS_NAMES = new String[] {
+ VpeUIMessages.TemplatesTableProvider_TagName,
+ VpeUIMessages.TemplatesTableProvider_TagForDisplay,
+ VpeUIMessages.TemplatesTableProvider_URI,
+ VpeUIMessages.TemplatesTableProvider_Children};
+
+ int[] COLUMNS_WIDTHS = new int[] {
+ 50, 50, 90, 40
+ };
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/VpeImportExportWizardsUtils.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/VpeImportExportWizardsUtils.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/wizards/VpeImportExportWizardsUtils.java 2010-05-17
13:51:21 UTC (rev 22119)
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * 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.vpe.editor.wizards;
+
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.template.VpeAnyData;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+
+public class VpeImportExportWizardsUtils {
+
+ /**
+ * Updates visual table with tags templates.
+ *
+ * @param tagsTable updated tags list
+ * @param tagsList current tags list
+ * @param clearTagsTable clears current tags table
+ */
+ public static void updateTagsTable(Table tagsTable, List<VpeAnyData> tagsList,
boolean clearTagsTable) {
+ /*
+ * Return when visual table hasn't been initialized.
+ */
+ if(tagsTable == null || tagsTable.isDisposed()) {
+ return;
+ }
+ /*
+ * Clear current visual table.
+ */
+ if (clearTagsTable) {
+ tagsTable.clearAll();
+ }
+ /*
+ * Return when tags templates list hasn't been initialized.
+ */
+ if (tagsList == null) {
+ return;
+ }
+ /*
+ * Remember current selection index
+ * and restore it at the end.
+ */
+ int selectionIndex = tagsTable.getSelectionIndex();
+ TableItem tableItem = null;
+ for (int i = 0; i < tagsList.size(); i++) {
+ if(tagsTable.getItemCount() > i) {
+ /*
+ * Use existed items
+ */
+ tableItem = tagsTable.getItem(i);
+ } else {
+ /*
+ * Add new item
+ */
+ tableItem = new TableItem(tagsTable, SWT.BORDER, i);
+ }
+ /*
+ * Fill in columns.
+ */
+ String[] itemColumnsData = new String[tagsTable.getColumnCount()];
+ for (int j = 0; j < itemColumnsData.length; j++) {
+ /*
+ * Getting values from tagList
+ */
+ itemColumnsData[j] = toVisualValue(getValueAt(tagsList, i, j));
+ }
+ /*
+ * Set cells text
+ */
+ tableItem.setText(itemColumnsData);
+ }
+
+ /*
+ * Restoring selection index
+ */
+ if (selectionIndex > 0 ) {
+ try {
+ tagsTable.setSelection(selectionIndex);
+ } catch (SWTException e) {
+ VpePlugin.getDefault().logError(
+ VpeUIMessages.COULD_NOT_SET_TABLE_SELECTION, e);
+ }
+ }
+ }
+
+ private static String getValueAt(List<VpeAnyData> tagsList, int row, int column)
{
+ String result = VpeUIMessages.LIST_IS_EMPTY;
+ if ((null != tagsList) && ((row >= 0) && (tagsList.size() > 0)
&& (row < tagsList.size()))) {
+ VpeAnyData tagItem = (VpeAnyData)tagsList.get(row);
+ switch(column){
+ case 0:
+ result = tagItem.getName();
+ break;
+ case 1:
+ result = tagItem.getTagForDisplay();
+ break;
+ case 2:
+ result = tagItem.getUri();
+ break;
+ case 3:
+ if(tagItem.isChildren()) {
+ result = VpeUIMessages.TemplatesTableProvider_Yes;
+ } else {
+ result = VpeUIMessages.TemplatesTableProvider_No;
+ }
+ break;
+ }
+ }
+ return result;
+ }
+
+ private static String toVisualValue(String v) {
+ if(v == null) return ""; //$NON-NLS-1$
+ if(v.indexOf('\n') >= 0) v = v.replace('\n', ' ');
+ if(v.indexOf('\t') >= 0) v = v.replace('\t', ' ');
+ if(v.indexOf('\r') >= 0) v = v.replace('\r', ' ');
+ return v;
+ }
+
+}
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-05-17
13:10:52 UTC (rev 22118)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-05-17
13:51:21 UTC (rev 22119)
@@ -155,5 +155,6 @@
public static String NONE_TEMPLATES_WERE_ADDED;
public static String COULD_NOT_SET_TABLE_SELECTION;
public static String CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT;
+ public static String LIST_IS_EMPTY;
}
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-05-17
13:10:52 UTC (rev 22118)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-05-17
13:51:21 UTC (rev 22119)
@@ -141,6 +141,7 @@
IMPORT_UNKNOWN_TAGS_PAGE_DESCRIPTION=Import unknown tags templates from external file
NONE_TEMPLATES_WERE_ADDED=None of the templates were added.
COULD_NOT_SET_TABLE_SELECTION=Could not set table selection.
+LIST_IS_EMPTY=List is empty
# Other messages
CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT=Cannot load taglibs from PageContext!
\ No newline at end of file
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeUiTests.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeUiTests.java 2010-05-17
13:10:52 UTC (rev 22118)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeUiTests.java 2010-05-17
13:51:21 UTC (rev 22119)
@@ -18,7 +18,6 @@
import org.jboss.tools.vpe.ui.test.dialog.VpeResourcesDialogTest;
import org.jboss.tools.vpe.ui.test.editor.CustomSashFormTest;
import org.jboss.tools.vpe.ui.test.preferences.VpeEditorPreferencesPageTest;
-import org.jboss.tools.vpe.ui.test.wizard.VpeImportExportUnknownTagsWizardsTest;
/**
* @author mareshkau
@@ -33,7 +32,6 @@
suite.addTestSuite(CustomSashFormTest.class);
suite.addTestSuite(VpePopupMenuTest.class);
suite.addTestSuite(VpeEditAnyDialogTest.class);
- suite.addTestSuite(VpeImportExportUnknownTagsWizardsTest.class);
return new VpeTestSetup(suite);
}