Author: dgolovin
Date: 2007-12-28 20:50:30 -0500 (Fri, 28 Dec 2007)
New Revision: 5480
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencePage.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/CompositeEditor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/IFieldEditorFactory.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1490
1. JUnit test for JBIDE-1490 was added
2. Javadoc comments were added
3. Coding style was improved to reduce amount of Checkstyle violations
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2007-12-29 01:49:25 UTC (rev
5479)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2007-12-29 01:50:30 UTC (rev
5480)
@@ -403,7 +403,9 @@
class="org.jboss.tools.seam.ui.preferences.SeamSettingsPreferencePage"
id="org.jboss.tools.seam.ui.propertyPages.SeamSettingsPreferencePage">
<enabledWhen>
- <adapt type="org.eclipse.core.resources.IProject"/>
+ <adapt type="org.eclipse.core.resources.IProject">
+ <test property="org.eclipse.core.resources.projectNature"
value="org.eclipse.jdt.core.javanature"/>
+ </adapt>
</enabledWhen>
</page>
</extension>
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencePage.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencePage.java 2007-12-29
01:49:25 UTC (rev 5479)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencePage.java 2007-12-29
01:50:30 UTC (rev 5480)
@@ -7,100 +7,81 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.seam.ui.preferences;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.jboss.tools.seam.core.ISeamProject;
-import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.project.facet.SeamRuntime;
import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
import org.jboss.tools.seam.ui.widget.editor.SeamRuntimeListFieldEditor;
/**
+ * Seam preference page that allows editing list of available Seam Runtimes:
+ * <ul>
+ * <li>define new </li>
+ * <li>change exists</li>
+ * <li>remove</li>
+ * </ul>
+ *
* @author eskimo
- *
*/
public class SeamPreferencePage extends PreferencePage implements
- IWorkbenchPreferencePage, PropertyChangeListener {
-
- public static String SEAM_PREFERENCES_ID =
"org.jboss.tools.common.model.ui.seam";
-
+ IWorkbenchPreferencePage {
+
/**
- *
+ * Seam Preferences page ID
*/
- SeamRuntimeListFieldEditor seamRuntimes
- = new
SeamRuntimeListFieldEditor("rtlist",SeamPreferencesMessages.SEAM_PREFERENCE_PAGE_SEAM_RUNTIMES,new
ArrayList<SeamRuntime>(Arrays.asList(SeamRuntimeManager.getInstance().getRuntimes())));
//$NON-NLS-1$
+ public static final String SEAM_PREFERENCES_ID =
"org.jboss.tools.common.model.ui.seam";
+ private static final int COLUMNS = 3;
+
+ SeamRuntimeListFieldEditor seamRuntimes = new SeamRuntimeListFieldEditor(
+ "rtlist", SeamPreferencesMessages.SEAM_PREFERENCE_PAGE_SEAM_RUNTIMES, new
ArrayList<SeamRuntime>(Arrays.asList(SeamRuntimeManager.getInstance().getRuntimes())));
//$NON-NLS-1$
+
SeamRuntime initialDefault;
/**
+ * Create contents of Seam preferences page. SeamRuntime list editor is
+ * created
*
+ * @return Control
*/
- public SeamPreferencePage() {
- }
-
- /**
- * @param title
- */
- public SeamPreferencePage(String title) {
- super(title);
- }
-
- /**
- * @param title
- * @param image
- */
- public SeamPreferencePage(String title, ImageDescriptor image) {
- super(title, image);
- }
-
- /**
- *
- */
@Override
protected Control createContents(Composite parent) {
Composite root = new Composite(parent, SWT.NONE);
- GridLayout gl = new GridLayout(3,false);
- root.setLayout(gl);
+ GridLayout gl = new GridLayout(COLUMNS, false);
+ root.setLayout(gl);
seamRuntimes.doFillIntoGrid(root);
initialDefault = SeamRuntimeManager.getInstance().getDefaultRuntime();
-
+
return root;
}
/**
+ * Inherited from IWorkbenchPreferencePage
*
+ * @param workbench
+ * {@link IWorkbench}
+ *
*/
public void init(IWorkbench workbench) {
}
/**
- *
+ * Save SeamRuntime list
*/
- public void propertyChange(PropertyChangeEvent arg0) {
- }
-
- /**
- *
- */
@Override
protected void performApply() {
for (SeamRuntime rt : seamRuntimes.getAddedSeamRuntimes()) {
@@ -111,27 +92,33 @@
SeamRuntimeManager.getInstance().removeRuntime(rt);
}
seamRuntimes.getRemoved().clear();
- if(initialDefault != null && seamRuntimes.getDefaultSeamRuntime() !=
initialDefault) {
+ if (initialDefault != null
+ && seamRuntimes.getDefaultSeamRuntime() != initialDefault) {
initialDefault.setDefault(false);
}
- Map<SeamRuntime,SeamRuntime> changed = seamRuntimes.getChangedSeamRuntimes();
- for (SeamRuntime c: changed.keySet()) {
+ Map<SeamRuntime, SeamRuntime> changed = seamRuntimes
+ .getChangedSeamRuntimes();
+ for (SeamRuntime c : changed.keySet()) {
SeamRuntime o = changed.get(c);
o.setHomeDir(c.getHomeDir());
o.setVersion(c.getVersion());
String oldName = o.getName();
String newName = c.getName();
- if(!oldName.equals(newName)) {
- SeamRuntimeManager.getInstance().changeRuntimeName(oldName, newName);
+ if (!oldName.equals(newName)) {
+ SeamRuntimeManager.getInstance().changeRuntimeName(oldName,
+ newName);
}
}
seamRuntimes.getChangedSeamRuntimes().clear();
- seamRuntimes.getDefaultSeamRuntime().setDefault(true);
+
+ if (seamRuntimes.getDefaultSeamRuntime() != null) {
+ seamRuntimes.getDefaultSeamRuntime().setDefault(true);
+ }
SeamRuntimeManager.getInstance().save();
}
/**
- *
+ * Restore original preferences values
*/
@Override
protected void performDefaults() {
@@ -140,10 +127,14 @@
performApply();
}
+ /**
+ * See {@link PreferencePage} for details
+ *
+ * @return Boolean
+ */
@Override
public boolean performOk() {
performApply();
return super.performOk();
}
-
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/CompositeEditor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/CompositeEditor.java 2007-12-29
01:49:25 UTC (rev 5479)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/CompositeEditor.java 2007-12-29
01:50:30 UTC (rev 5480)
@@ -19,8 +19,10 @@
import java.util.List;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.jboss.tools.seam.ui.SeamUIMessages;
@@ -37,19 +39,27 @@
@Override
public void doFillIntoGrid(Object parent) {
- Assert.isTrue(parent instanceof Composite,
SeamUIMessages.COMPOSITE_EDITOR_PARENT_CONTROL_SHOULD_BE_COMPOSITE);
- Assert.isTrue(((Composite)parent).getLayout() instanceof
GridLayout,SeamUIMessages.COMPOSITE_EDITOR_EDITOR_SUPPORTS_ONLY_GRID_LAYOUT);
+ Assert.isTrue(parent instanceof Composite,
+ SeamUIMessages.COMPOSITE_EDITOR_PARENT_CONTROL_SHOULD_BE_COMPOSITE);
+ Assert.isTrue(((Composite) parent).getLayout() instanceof GridLayout,
+ SeamUIMessages.COMPOSITE_EDITOR_EDITOR_SUPPORTS_ONLY_GRID_LAYOUT);
+
Composite aComposite = (Composite) parent;
- Control[] controls = (Control[])getEditorControls(aComposite);
- GridLayout gl = (GridLayout)((Composite)parent).getLayout();
+ Control[] controls = (Control[]) getEditorControls(aComposite);
+ GridLayout gl = (GridLayout) ((Composite) parent).getLayout();
- for(int i=0;i<controls.length;i++) {
- GridData gd = new GridData();
- gd.horizontalSpan = i==1?gl.numColumns-controls.length+1:1;
- gd.horizontalAlignment = GridData.FILL;
- gd.grabExcessHorizontalSpace = (i==1);
- controls[i].setLayoutData(gd);
- }
+ for (int i = 0; i < controls.length; i++) {
+ GridData gd = new GridData();
+ gd.horizontalSpan = i == 1 ? gl.numColumns - controls.length + 1 : 1;
+ if (controls[i] instanceof Combo && i == (controls.length - 1)) {
+ gd.horizontalAlignment = SWT.BEGINNING;
+ } else {
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = (i == 1);
+ }
+
+ controls[i].setLayoutData(gd);
+ }
}
List<Control> controls = new ArrayList<Control>();
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/IFieldEditorFactory.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/IFieldEditorFactory.java 2007-12-29
01:49:25 UTC (rev 5479)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/IFieldEditorFactory.java 2007-12-29
01:50:30 UTC (rev 5480)
@@ -104,7 +104,7 @@
*/
IFieldEditor createUneditableTextEditor(String jdbcDriverClassName,
String string, String string2);
-
+
/**
*
* @param name
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java 2007-12-29
01:49:25 UTC (rev 5479)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java 2007-12-29
01:50:30 UTC (rev 5480)
@@ -7,10 +7,9 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.seam.ui.widget.editor;
-import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
@@ -18,7 +17,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -28,9 +26,12 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
-import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
@@ -50,136 +51,168 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
-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.XChildrenEditor;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.project.facet.SeamRuntime;
-import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
import org.jboss.tools.seam.core.project.facet.SeamVersion;
import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
import org.jboss.tools.seam.ui.SeamUIMessages;
import org.jboss.tools.seam.ui.internal.project.facet.ValidatorFactory;
import org.jboss.tools.seam.ui.wizard.SeamFormWizard;
/**
+ * Control that have table and buttons for editing Seam Runtime list
+ *
* @author eskimo
- *
+ *
*/
-public class SeamRuntimeListFieldEditor extends BaseFieldEditor implements
ISelectionChangedListener, SelectionListener, CommandBarListener {
- static String REMOVE = "&Remove";
- CheckboxTableViewer tableView = null;
- Composite root = null;
- protected CommandBar bar = new CommandBar();
+public class SeamRuntimeListFieldEditor extends BaseFieldEditor {
+
+ // ------------------------------------------------------------------------
+ // Layout parameters
+ // ------------------------------------------------------------------------
+
+ static final int GL_COLUMNS = 2;
+ static final int GL_HINT_HEIGHT = 200;
+ static final int TC_DEFAULT_WIDTH = 21;
+ static final int TC_NAME_WIDTH = 100;
+ static final int TC_VERSION_WIDTH = 50;
+ static final int TC_PATH_WIDTH = 100;
+
+ // ------------------------------------------------------------------------
+ // Field declarations
+ // ------------------------------------------------------------------------
+
+ private CheckboxTableViewer tableView = null;
+
+ private Composite root = null;
+
+ private Map<SeamRuntime, SeamRuntime> changed = new HashMap<SeamRuntime,
SeamRuntime>();
+
+ private SeamRuntime checkedElement = null;
+
+ private List<SeamRuntime> added = new ArrayList<SeamRuntime>();
+
+ private List<SeamRuntime> removed = new ArrayList<SeamRuntime>();
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
/**
+ * Control for editing SeamRuntime list
+ *
* @param name
+ * String
* @param label
+ * String
* @param defaultValue
+ * Object
*/
- public SeamRuntimeListFieldEditor(String name, String label, Object defaultValue) {
+ public SeamRuntimeListFieldEditor(String name, String label,
+ Object defaultValue) {
super(name, label, defaultValue);
- bar.addCommandBarListener(this);
}
- private SeamRuntime checkedElement = null;
-
/**
+ * TBD
*
- * @return
+ * @return List<SeamRuntime>
*/
public SeamRuntime getDefaultSeamRuntime() {
return checkedElement;
}
-
- private List<SeamRuntime> added = new ArrayList<SeamRuntime>();
-
+
/**
+ * TBD
*
- * @return
+ * @return List<SeamRuntime>
*/
public List<SeamRuntime> getAddedSeamRuntimes() {
return added;
}
-
- private Map<SeamRuntime,SeamRuntime> changed = new
HashMap<SeamRuntime,SeamRuntime>();
-
+
/**
+ * TBD
*
- * @return
+ * @return List<SeamRuntime>
*/
- public Map<SeamRuntime,SeamRuntime> getChangedSeamRuntimes() {
+ public Map<SeamRuntime, SeamRuntime> getChangedSeamRuntimes() {
return changed;
}
-
- private List<SeamRuntime> removed = new ArrayList<SeamRuntime>();
-
+
/**
+ * TBD
*
- * @return
+ * @return List<SeamRuntime>
*/
public List<SeamRuntime> getRemoved() {
return removed;
}
-
+
+ /**
+ * TBD
+ *
+ * @param composite
+ * Object - instance of Composite
+ * @return Object[]
+ */
@Override
public Object[] getEditorControls(Object composite) {
-
- root = new Composite((Composite)composite,SWT.NONE);
- root.setLayout(new GridLayout(2,false));
- GridData gd = new GridData();
- gd.horizontalAlignment = GridData.FILL;
- gd.grabExcessHorizontalSpace = true;
- root.setLayoutData(gd);
-
- tableView = CheckboxTableViewer.newCheckList(root,
- SWT.V_SCROLL|SWT.BORDER|SWT.FULL_SELECTION|SWT.SINGLE);
-
+
+ root = new Composite((Composite) composite, SWT.NONE);
+ root.setLayout(new GridLayout(GL_COLUMNS, false));
+ GridData gd = new GridData();
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ root.setLayoutData(gd);
+
+ tableView = CheckboxTableViewer.newCheckList(root, SWT.V_SCROLL
+ | SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
+
gd = new GridData();
- gd.heightHint = 200;
- gd.horizontalAlignment = GridData.FILL;
- gd.grabExcessHorizontalSpace = true;
-
+ gd.heightHint = GL_HINT_HEIGHT;
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = true;
+
tableView.getControl().setLayoutData(gd);
- tableView.addSelectionChangedListener(this);
-
- createCommandBar(root);
- bar.setEnabled(REMOVE, false);
- bar.setEnabled(XChildrenEditor.EDIT, false);
-
- TableColumn tc1 = new TableColumn(tableView.getTable(),SWT.CENTER);
- tc1.setWidth(21);
+
+ TableColumn tc1 = new TableColumn(tableView.getTable(), SWT.CENTER);
+ tc1.setWidth(TC_DEFAULT_WIDTH);
tc1.setResizable(false);
-
- TableColumn tc2 = new TableColumn(tableView.getTable(),SWT.LEFT);
- tc2.setWidth(100);
- tc2.setText(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NAME);
- TableColumn tc3 = new TableColumn(tableView.getTable(),SWT.LEFT);
- tc3.setWidth(50);
- tc3.setText(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_VERSION);
-
- TableColumn tc4 = new TableColumn(tableView.getTable(),SWT.LEFT);
- tc4.setWidth(100);
+ TableColumn tc2 = new TableColumn(tableView.getTable(), SWT.LEFT);
+ tc2.setWidth(TC_NAME_WIDTH);
+ tc2.setText(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NAME);
+
+ TableColumn tc3 = new TableColumn(tableView.getTable(), SWT.LEFT);
+ tc3.setWidth(TC_VERSION_WIDTH);
+ tc3.setText(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_VERSION);
+
+ TableColumn tc4 = new TableColumn(tableView.getTable(), SWT.LEFT);
+ tc4.setWidth(TC_PATH_WIDTH);
tc4.setText(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_PATH);
-
+
tableView.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
- if(inputElement instanceof List)
- return ((List<SeamRuntime>)inputElement).toArray();
- else
- throw new
IllegalArgumentException(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_INPUTELEMENT_MUST_BE
+
- SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_AN_INSTANCEOF_OF_LIST);
+ if (inputElement instanceof List) {
+ return ((List<SeamRuntime>) inputElement).toArray();
+ } else {
+ throw new IllegalArgumentException(
+ SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_INPUTELEMENT_MUST_BE
+ + SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_AN_INSTANCEOF_OF_LIST);
+ }
}
public void dispose() {
@@ -193,135 +226,222 @@
tableView.setLabelProvider(new ITableLabelProvider() {
- public void addListener(ILabelProviderListener listener) {}
+ private static final int TC_DEFAULT_NUMBER = 0;
+ private static final int TC_NAME_NUMBER = 1;
+ private static final int TC_VERSION_NUMBER = 2;
+ private static final int TC_PATH_NUMBER = 3;
- public void dispose() { }
+ public void addListener(ILabelProviderListener listener) {
+ }
+ public void dispose() {
+ }
+
public boolean isLabelProperty(Object element, String property) {
return false;
}
- public void removeListener(ILabelProviderListener listener) {}
+ public void removeListener(ILabelProviderListener listener) {
+ }
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
public String getColumnText(Object element, int columnIndex) {
- SeamRuntime rt = (SeamRuntime)element;
- if(columnIndex==0) return ""; //$NON-NLS-1$
- if(columnIndex==1) return rt.getName();
- if(columnIndex==2) return rt.getVersion().toString();
- if(columnIndex==3) return rt.getHomeDir();
+ SeamRuntime rt = (SeamRuntime) element;
+ if (columnIndex == TC_DEFAULT_NUMBER) {
+ return ""; //$NON-NLS-1$
+ }
+ if (columnIndex == TC_NAME_NUMBER) {
+ return rt.getName();
+ }
+ if (columnIndex == TC_VERSION_NUMBER) {
+ return rt.getVersion().toString();
+ }
+ if (columnIndex == TC_PATH_NUMBER) {
+ return rt.getHomeDir();
+ }
return ""; //$NON-NLS-1$
}
});
-
+
tableView.setInput(getValue());
tableView.getTable().setLinesVisible(true);
tableView.getTable().setHeaderVisible(true);
- tableView.addCheckStateListener( new ICheckStateListener () {
+ tableView.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
- if(event.getChecked()) {
- tableView.setCheckedElements(new Object[]{event.getElement()});
- //checkedElement.setDefault(false);
- checkedElement = (SeamRuntime)event.getElement();
- //checkedElement.setDefault(true);
- } else if(checkedElement==event.getElement()) {
- tableView.setCheckedElements(new Object[]{event.getElement()});
+ if (event.getChecked()) {
+ SeamRuntime deselRt = null;
+ SeamRuntime selRt = (SeamRuntime) event.getElement();
+ Object[] selRts = tableView.getCheckedElements();
+
+ for (int i = 0; i < selRts.length; i++) {
+ SeamRuntime rt = (SeamRuntime) selRts[i];
+ if (rt.getVersion() == selRt.getVersion()
+ && rt != selRt) {
+ deselRt = rt;
+ break;
+ }
+ }
+
+ if (deselRt != null) {
+ Object[] newChecked = new Object[selRts.length - 1];
+ int i = 0;
+ for (Object object : selRts) {
+ SeamRuntime rt = (SeamRuntime) object;
+ if (rt.getVersion() != selRt.getVersion()
+ || rt == selRt) {
+ newChecked[i] = rt;
+ i++;
+ }
+ }
+ tableView.setCheckedElements(newChecked);
+ }
+
+ // checkedElement.setDefault(false);
+ checkedElement = (SeamRuntime) event.getElement();
+ // checkedElement.setDefault(true);
}
pcs.firePropertyChange(getName(), null, getValue());
}
});
-
+
for (SeamRuntime rt : (List<SeamRuntime>) getValue()) {
- if(rt.isDefault()) {
- tableView.setCheckedElements(new Object[]{rt});
+ if (rt.isDefault()) {
+ tableView.setCheckedElements(new Object[] {rt});
checkedElement = rt;
break;
}
}
-
- return new Control[]{tableView.getControl()};
+ ActionPanel actionPanel = new ActionPanel(root, new BaseAction[] {
+ new AddAction(), new EditAction(), new RemoveAction()});
+ tableView.addSelectionChangedListener(actionPanel);
+ return new Control[] {root};
}
+ /**
+ * Return array of Controls that forms and editor
+ *
+ * @return Control[]
+ */
@Override
public Object[] getEditorControls() {
- return new Control[]{root};
+ return new Control[] {root};
}
+ /**
+ * Return number of controls in editor
+ *
+ * @return int
+ */
@Override
public int getNumberOfControls() {
return 1;
}
/**
+ * Fill wizard page with editors
*
* @param parent
+ * Composite - parent composite
*/
@Override
public void doFillIntoGrid(Object parent) {
- Assert.isTrue(parent instanceof Composite,
- SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_PARENT_CONTROL_SHOULD_BE_COMPOSITE);
- Assert.isTrue(((Composite)parent).getLayout()
- instanceof
GridLayout,SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_EDITOR_SUPPORTS_ONLY_GRID_LAYOUT);
+ Assert
+ .isTrue(
+ parent instanceof Composite,
+ SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_PARENT_CONTROL_SHOULD_BE_COMPOSITE);
+ Assert
+ .isTrue(
+ ((Composite) parent).getLayout() instanceof GridLayout,
+ SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_EDITOR_SUPPORTS_ONLY_GRID_LAYOUT);
Composite aComposite = (Composite) parent;
- Control[] controls = (Control[])getEditorControls(aComposite);
- GridLayout gl = (GridLayout)((Composite)parent).getLayout();
-
+ Control[] controls = (Control[]) getEditorControls(aComposite);
+ GridLayout gl = (GridLayout) ((Composite) parent).getLayout();
+
GridData gd = new GridData();
gd.horizontalSpan = gl.numColumns;
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.FILL;
- ((Control)getEditorControls()[0]).setLayoutData(gd);
+ ((Control) getEditorControls()[0]).setLayoutData(gd);
}
- public static class SeamRuntimeWizardPage extends WizardPage implements
PropertyChangeListener {
+ /**
+ * Wizard page for editing Seam Runtime parameters
+ *
+ * @author eskimo
+ */
+ public static class SeamRuntimeWizardPage extends WizardPage implements
+ PropertyChangeListener {
+ private static final String SRT_NAME = "name";
+ private static final String SRT_HOMEDIR = "homeDir";
+ private static final String SRT_VERSION = "version";
+
+ private static final int GL_PARENT_COLUMNS = 1;
+ private static final int GL_CONTENT_COLUMNS = 3;
+
List<SeamRuntime> value = null;
-
+
IFieldEditor name = IFieldEditorFactory.INSTANCE.createTextEditor(
- "name", SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NAME2, "");
//$NON-NLS-1$ //$NON-NLS-2$
-
+ SRT_NAME, SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NAME2,
+ ""); //$NON-NLS-1$
+
IFieldEditor version = null;
-
- IFieldEditor homeDir = IFieldEditorFactory.INSTANCE.createBrowseFolderEditor(
- "homeDir", SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_HOME_FOLDER,
""); //$NON-NLS-1$ //$NON-NLS-2$
-
- IFieldEditor dflt = IFieldEditorFactory.INSTANCE.createCheckboxEditor(
- "default",
SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_USE_AS_DEFAULT, false); //$NON-NLS-1$
-
+
+ IFieldEditor homeDir = IFieldEditorFactory.INSTANCE
+ .createBrowseFolderEditor(
+ SRT_HOMEDIR,
+ SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_HOME_FOLDER,
+ ""); //$NON-NLS-1$
+
SeamRuntime current = null;
List<SeamVersion> validSeamVersions = null;
-
+
/**
- * @param parent
- * @param style
+ * Create Seam Runtime editing wizard page with all SeamVersion in
+ * version selection combo
+ *
+ * @param editedList
+ * List<SeamVersion> - list of existing Seam Runtimes
*/
public SeamRuntimeWizardPage(List<SeamRuntime> editedList) {
- this(editedList, null);
+ this(editedList, (List<SeamVersion>) null);
}
/**
- * @param parent
- * @param style
+ * Create Seam Runtime editing wizard page with validSeamVersions in
+ * version selection combo
+ *
+ * @param editedList
+ * List<SeamVersion> - list of existing Seam Runtimes
+ * @param validSeamVersions
+ * List<SeamVersion> - list of allowed Seam Versions
*/
- public SeamRuntimeWizardPage(List<SeamRuntime> editedList,
List<SeamVersion> validSeamVersions) {
- super(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NEW_SEAM_RUNTIME);
- if(validSeamVersions==null) {
+ public SeamRuntimeWizardPage(List<SeamRuntime> editedList,
+ List<SeamVersion> validSeamVersions) {
+ super(
+ SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NEW_SEAM_RUNTIME);
+ if (validSeamVersions == null) {
this.version = IFieldEditorFactory.INSTANCE.createComboEditor(
- "version", SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_VERSION2,
Arrays.asList( //$NON-NLS-1$
- new String[]{SeamVersion.SEAM_1_2.toString(), SeamVersion.SEAM_2_0.toString()}),
- SeamVersion.SEAM_1_2.toString(), false);
+ SRT_VERSION,
+ SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_VERSION2,
+ Arrays.asList(new String[] {
+ SeamVersion.SEAM_1_2.toString(),
+ SeamVersion.SEAM_2_0.toString()}),
+ SeamVersion.SEAM_1_2.toString(), false);
this.validSeamVersions = new ArrayList<SeamVersion>();
this.validSeamVersions.add(SeamVersion.SEAM_1_2);
- this.validSeamVersions.add(SeamVersion.SEAM_2_0);
+ this.validSeamVersions.add(SeamVersion.SEAM_2_0);
} else {
this.version = IFieldEditorFactory.INSTANCE.createComboEditor(
- "version", SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_VERSION2,
validSeamVersions,
- SeamVersion.SEAM_1_2.toString(), false);
- this.validSeamVersions = validSeamVersions;
+ SRT_VERSION,
+ SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_VERSION2,
+ validSeamVersions, SeamVersion.SEAM_1_2.toString(),
+ false);
+ this.validSeamVersions = validSeamVersions;
}
setMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CREATE_A_SEAM_RUNTIME);
@@ -332,34 +452,56 @@
}
/**
+ * Wizard page for editing SeamRuntime were is only single version of
+ * SeamRuntime can be used
*
+ * @param editedList
+ * List<SeamRuntime> - TBD
+ * @param validVersion
+ * SeamVersion - TBD
*/
+ public SeamRuntimeWizardPage(List<SeamRuntime> editedList,
+ SeamVersion validVersion) {
+ this(editedList, Arrays.asList(new SeamVersion[] {validVersion}));
+ }
+
+ /**
+ * Create Wizard page content
+ *
+ * @param parent
+ * Composite - parent composite
+ */
public void createControl(Composite parent) {
- parent.setLayout(new GridLayout(1, false));
+ parent.setLayout(new GridLayout(GL_PARENT_COLUMNS, false));
GridData dg = new GridData();
dg.horizontalAlignment = GridData.FILL;
dg.grabExcessHorizontalSpace = true;
Composite root = new Composite(parent, SWT.NONE);
root.setLayoutData(dg);
- GridLayout gl = new GridLayout(3, false);
+ GridLayout gl = new GridLayout(GL_CONTENT_COLUMNS, false);
root.setLayout(gl);
homeDir.doFillIntoGrid(root);
homeDir.addPropertyChangeListener(this);
name.doFillIntoGrid(root);
name.addPropertyChangeListener(this);
version.doFillIntoGrid(root);
+ version.setValue(validSeamVersions.get(0));
version.addPropertyChangeListener(this);
setPageComplete(false);
setControl(root);
}
/**
+ * Process evt: setup default values based on Seam Home folder and
+ * validate user input
*
+ * @param evt
+ * PropertyChangeEvent describes changes in wizard
*/
- public void propertyChange(PropertyChangeEvent evt) {
+ public void propertyChange(java.beans.PropertyChangeEvent evt) {
if ("homeDir".equals(evt.getPropertyName())) {
- if (name.getValueAsString() == null ||
- "".equals(name.getValueAsString().trim())) {
+ if (name.getValueAsString() == null
+ || "".equals(name.getValueAsString().trim())) {
String homeDirName = homeDir.getValueAsString();
if (homeDirName != null && !"".equals(homeDirName.trim())) {
File folder = new File(homeDirName);
@@ -367,147 +509,219 @@
}
name.setValue(homeDirName);
- String seamVersion = getSeamVersion(homeDir.getValueAsString());
+ String seamVersion = getSeamVersion(homeDir
+ .getValueAsString());
if (validSeamVersions != null) {
for (SeamVersion ver : validSeamVersions) {
- if
(seamVersion.matches(ver.toString().replace(".","\\.")+".*"))
{
+ if (seamVersion.matches(ver.toString().replace(".",
+ "\\.")
+ + ".*")) {
version.setValue(ver.toString());
break;
}
}
}
}
- }
- if(name.getValueAsString()==null || "".equals( //$NON-NLS-1$
- name.getValueAsString().toString().trim())) {
- setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NAME_CANNOT_BE_EMPTY);
- setPageComplete(false);
- return;
+ }
+
+ if (name.getValueAsString() == null || "".equals(//$NON-NLS-1$
+ name.getValueAsString().toString().trim())) {
+ setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NAME_CANNOT_BE_EMPTY);
+ setPageComplete(false);
+ return;
+ }
+
+ if (!name.getValueAsString().matches(
+ "[a-zA-Z_][a-zA-Z0-9_\\-\\. ]*")) { //$NON-NLS-1$
+ setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_RUNTIME_NAME_IS_NOT_CORRECT);
+ setPageComplete(false);
+ return;
+ }
+ for (SeamRuntime rt : value) {
+ if (current != null && current.getName().equals(rt.getName())) {
+ continue;
}
-
- if(!name.getValueAsString().matches("[a-zA-Z_][a-zA-Z0-9_\\-\\. ]*")) {
//$NON-NLS-1$
- setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_RUNTIME_NAME_IS_NOT_CORRECT);
+ if (rt.getName().equals(name.getValueAsString())) {
+ setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_RUNTIME
+ + name.getValueAsString()
+ + SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_ALREADY_EXISTS);
setPageComplete(false);
return;
}
- for (SeamRuntime rt : value) {
- if(current != null && current.getName().equals(rt.getName())) continue;
- if(rt.getName().equals(name.getValueAsString())) {
- setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_RUNTIME+name.getValueAsString()+
SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_ALREADY_EXISTS);
- setPageComplete(false);
- return;
- }
- }
-
- if(current != null && current.getName().equals(name.getValueAsString())
- && current.getVersion().toString().equals(version.getValueAsString())
- && current.getHomeDir().equals(homeDir.getValueAsString())
- ) {
- setErrorMessage(null);
- setPageComplete(false);
- return;
- }
+ }
- if(homeDir.getValueAsString()==null ||
"".equals(homeDir.getValueAsString().trim())) { //$NON-NLS-1$
- setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_PATH_TO_SEAM_HOME_DIRECTORY_CANNOT_BE_EMPTY);
- setPageComplete(false);
- return;
- }
-
- String seamVersion = getSeamVersion(homeDir.getValueAsString());
- if(seamVersion == null){
- setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_FIND_JBOSS_SEAM_JAR);
- setPageComplete(false);
- return;
- }else if("".equals(seamVersion)) { //$NON-NLS-1$
- setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_OBTAIN_SEAM_VERSION_NUMBER);
- setPageComplete(false);
- return;
- } else
if(!seamVersion.matches(version.getValueAsString().replace(".","\\.")+".*"))
{ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_THE_SELECTED_SEAM_APPEARS_TO_BE_OF_INCOMATIBLE_VERSION
+ seamVersion + "'"); //$NON-NLS-1$
- setPageComplete(false);
- return;
- }
-
- Map errors = ValidatorFactory.JBOSS_SEAM_HOME_FOLDER_VALIDATOR.validate(
- homeDir.getValueAsString(), seamVersion);
- if( errors != ValidatorFactory.NO_ERRORS) {
- setErrorMessage(errors.get(ISeamFacetDataModelProperties.JBOSS_SEAM_HOME).toString());
- setPageComplete(false);
- return;
- }
-
-
+ if (current != null
+ && current.getName().equals(name.getValueAsString())
+ && current.getVersion().toString().equals(
+ version.getValueAsString())
+ && current.getHomeDir().equals(homeDir.getValueAsString())) {
+ setErrorMessage(null);
+ setPageComplete(false);
+ return;
+ }
+
+ if (homeDir.getValueAsString() == null
+ || "".equals(homeDir.getValueAsString().trim())) { //$NON-NLS-1$
+ setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_PATH_TO_SEAM_HOME_DIRECTORY_CANNOT_BE_EMPTY);
+ setPageComplete(false);
+ return;
+ }
+
+ String seamVersion = getSeamVersion(homeDir.getValueAsString());
+ if (seamVersion == null) {
+ setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_FIND_JBOSS_SEAM_JAR);
+ setPageComplete(false);
+ return;
+ } else if ("".equals(seamVersion)) { //$NON-NLS-1$
+ setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_OBTAIN_SEAM_VERSION_NUMBER);
+ setPageComplete(false);
+ return;
+ } else if (!seamVersion.matches(version.getValueAsString().replace(
+ ".", "\\.") + ".*")) { //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_THE_SELECTED_SEAM_APPEARS_TO_BE_OF_INCOMATIBLE_VERSION
+ + seamVersion + "'"); //$NON-NLS-1$
+ setPageComplete(false);
+ return;
+ }
+
+ Map errors = ValidatorFactory.JBOSS_SEAM_HOME_FOLDER_VALIDATOR
+ .validate(homeDir.getValueAsString(), seamVersion);
+ if (errors != ValidatorFactory.NO_ERRORS) {
+ setErrorMessage(errors.get(
+ ISeamFacetDataModelProperties.JBOSS_SEAM_HOME)
+ .toString());
+ setPageComplete(false);
+ return;
+ }
+
setErrorMessage(null);
setPageComplete(true);
}
-
+
+ /**
+ * Return Seam runtime version obtained form jboss-seam.jar manifest
+ * 'Seam Version' property
+ *
+ * @param path
+ * path to Seam home folder
+ * @return String value of 'Seam Version' manifest property
+ */
public static String getSeamVersion(String path) {
File seamJarFile = new File(path, "jboss-seam.jar"); //$NON-NLS-1$
- if(!seamJarFile.exists()) {
- seamJarFile = new File(path, "lib/jboss-seam.jar"); // hack to make it work
for seam2
- if(!seamJarFile.exists()) return null;
+ if (!seamJarFile.exists()) {
+ seamJarFile = new File(path, "lib/jboss-seam.jar"); // hack to
+ // make it
+ // work for
+ // seam2
+ if (!seamJarFile.exists()) {
+ return null;
+ }
}
- InputStream str=null;
+ InputStream str = null;
ZipFile seamJar;
try {
seamJar = new ZipFile(seamJarFile);
- ZipFileStructureProvider provider = new ZipFileStructureProvider(seamJar);
+ ZipFileStructureProvider provider = new ZipFileStructureProvider(
+ seamJar);
ZipEntry entry = seamJar.getEntry("META-INF/MANIFEST.MF"); //$NON-NLS-1$
str = provider.getContents(entry);
Properties manifest = new Properties();
manifest.load(str);
- Object sv =
manifest.get(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_SEAM_VERSION);
- return sv==null?"":sv.toString(); //$NON-NLS-1$
-
+ Object sv = manifest
+ .get(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_SEAM_VERSION);
+ return sv == null ? "" : sv.toString(); //$NON-NLS-1$
+
} catch (IOException e) {
- SeamCorePlugin.getPluginLog().logError(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_READ_JAR_FILE,e);
+ SeamCorePlugin
+ .getPluginLog()
+ .logError(
+ SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_READ_JAR_FILE,
+ e);
} finally {
- if(str!=null)
+ if (str != null) {
try {
str.close();
} catch (IOException e) {
- // nothing to do with that
+ SeamGuiPlugin.getPluginLog().logError(e);
}
+ }
}
return ""; //$NON-NLS-1$
}
-
+
/**
+ * Return Seam Runtime instance initialized by user input
*
- * @return
+ * @return SeamRuntime instance
*/
public SeamRuntime getRuntime() {
SeamRuntime newRt = new SeamRuntime();
newRt.setName(name.getValueAsString());
- newRt.setVersion(SeamVersion.parseFromString(version.getValueAsString()));
+ newRt.setVersion(SeamVersion.parseFromString(version
+ .getValueAsString()));
newRt.setHomeDir(homeDir.getValueAsString());
- //newRt.setDefault((Boolean)dflt.getValue());
return newRt;
}
}
-
+
+ /**
+ * Wizard collect information and creates new SeamRuntime instances.
+ *
+ * @author eskimo
+ */
public static class SeamRuntimeNewWizard extends Wizard {
SeamRuntimeWizardPage page1 = null;
List<SeamRuntime> added = null;
List<SeamRuntime> value = null;
- public SeamRuntimeNewWizard(List<SeamRuntime> value, List<SeamRuntime>
added, List<SeamVersion> validSeamVersions) {
+ /**
+ * Constructor for creating a SeamRuntime wizard with default title and
+ * one page to edit new Seam Runtime parameters as name, Seam version
+ * and path to Seam home folder. Wizard allows constraining the list of
+ * Seam version to handle creating of Seam Runtime form Seam Facet
+ * Installation page.
+ *
+ * @param exist
+ * list of exists SeamRuntimes, that will be used during
+ * created SeamRuntime name validation
+ * @param added
+ * List<SeamRuntime> - TBD
+ * @param validSeamVersions
+ * List<SeamRuntime> - List of Seam Runtime versions
+ * that can be created
+ */
+ public SeamRuntimeNewWizard(List<SeamRuntime> exist,
+ List<SeamRuntime> added, List<SeamVersion> validSeamVersions) {
super();
setWindowTitle(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NEW_SEAM_RUNTIME);
- page1 = new SeamRuntimeWizardPage(value, validSeamVersions);
+ page1 = new SeamRuntimeWizardPage(exist, validSeamVersions);
addPage(page1);
- this.value = value;
+ this.value = exist;
this.added = added;
}
- public SeamRuntimeNewWizard(List<SeamRuntime> value, List<SeamRuntime>
added) {
- this(value, added, null);
+ /**
+ * Create wizard that shows all available seam version in version selection
+ * combobox
+ *
+ * @param existing
+ * List of existing Seam Runtimes
+ * @param added
+ * TBD
+ */
+ public SeamRuntimeNewWizard(List<SeamRuntime> existing,
+ List<SeamRuntime> added) {
+ this(existing, added, null);
}
-
+
+ /**
+ * Do finish steps
+ *
+ * @return boolean
+ */
@Override
public boolean performFinish() {
SeamRuntime rt = page1.getRuntime();
@@ -517,20 +731,43 @@
}
}
+ /**
+ * Wizard for editing Seam Runrtime parameters: name, version and path to
+ * home folder
+ *
+ * @author eskimo
+ */
public static class SeamRuntimeEditWizard extends Wizard {
SeamRuntimeWizardPage page1 = null;
List<SeamRuntime> added = null;
Map<SeamRuntime, SeamRuntime> changed = null;
List<SeamRuntime> value = null;
SeamRuntime source = null;
- public SeamRuntimeEditWizard(List<SeamRuntime> value, SeamRuntime source,
List<SeamRuntime> added, Map<SeamRuntime, SeamRuntime> changed) {
+
+ /**
+ * Constructor with almost all initialization parameters
+ *
+ * @param existing
+ * List<SeamRuntime> - edited list of Seam Runtimes
+ * @param source
+ * SeamRuntime - edited Seam Runtime
+ * @param added
+ * List<SeamRuntime> - TBD
+ * @param changed
+ * List<SeamRuntime> - TBD
+ */
+ public SeamRuntimeEditWizard(List<SeamRuntime> existing,
+ SeamRuntime source, List<SeamRuntime> added,
+ Map<SeamRuntime, SeamRuntime> changed) {
super();
setWindowTitle(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_EDIT_SEAM_RUNTIME);
- page1 = new SeamRuntimeWizardPage(value);
- page1.setMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_MODIFY_SEAM_RUNTIME);
- page1.setTitle(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_EDIT_SEAM_RUNTIME);
+ page1 = new SeamRuntimeWizardPage(existing);
+ page1
+ .setMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_MODIFY_SEAM_RUNTIME);
+ page1
+ .setTitle(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_EDIT_SEAM_RUNTIME);
addPage(page1);
- this.value = value;
+ this.value = existing;
this.added = added;
this.changed = changed;
this.source = source;
@@ -539,24 +776,29 @@
page1.version.setValue(source.getVersion().toString());
page1.current = source;
}
-
+
+ /**
+ * Perform operations to finish editing Seam Runtime parameters
+ *
+ * @return boolean - always true
+ */
@Override
public boolean performFinish() {
SeamRuntime rt = page1.getRuntime();
- if(rt.getName().equals(source.getName())
- && rt.getVersion().toString().equals(source.getVersion().toString())
- && rt.getHomeDir().equals(source.getHomeDir())
- ) {
+ if (rt.getName().equals(source.getName())
+ && rt.getVersion().toString().equals(
+ source.getVersion().toString())
+ && rt.getHomeDir().equals(source.getHomeDir())) {
return true;
}
- if(added.contains(source) || changed.containsKey(source)) {
+ if (added.contains(source) || changed.containsKey(source)) {
source.setName(rt.getName());
source.setHomeDir(rt.getName());
source.setVersion(rt.getVersion());
} else {
changed.put(rt, source);
int i = value.indexOf(source);
- if(i >= 0) {
+ if (i >= 0) {
value.set(i, rt);
} else {
value.remove(source);
@@ -568,145 +810,355 @@
}
/**
- * @see
org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ * Composite that holds list of BaseActions and presents them as column of
+ * buttons
+ *
+ * @author eskimo
*/
- public void selectionChanged(SelectionChangedEvent event) {
- IStructuredSelection selection = (IStructuredSelection)event.getSelection();
- selectionChanged((SeamRuntime)selection.getFirstElement());
+ public static class ActionPanel extends Composite implements
+ ISelectionChangedListener {
+
+ private BaseAction[] actions = null;
+
+ /**
+ * Constructor creates panel with style, grid layout and buttons
+ * represented the actions
+ *
+ * @param parent
+ * Composite
+ * @param style
+ * int
+ * @param actions
+ * BaseAction[]
+ */
+ public ActionPanel(Composite parent, int style, BaseAction[] actions) {
+ super(parent, style);
+ this.actions = actions;
+ setLayout(new GridLayout(1, false));
+ GridData gd = new GridData();
+ gd.horizontalAlignment = GridData.FILL;
+ gd.verticalAlignment = GridData.FILL;
+ gd.grabExcessVerticalSpace = true;
+ setLayoutData(gd);
+ for (BaseAction action : this.actions) {
+ new ActionButton(this, SWT.PUSH, action);
+ }
+ }
+
+ /**
+ * Constructor creates panel with default style, grid layout and buttons
+ * represented the actions
+ *
+ * @param parent
+ * Composite
+ * @param actions
+ * BaseAction[]
+ */
+ public ActionPanel(Composite parent, BaseAction[] actions) {
+ this(parent, SWT.NONE, actions);
+ }
+
+ /**
+ * Listen to the selection changes and update actions state
+ * (enable/disable)
+ *
+ * @param event
+ * SelectionChangeEvent
+ * @see
org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ for (BaseAction action : actions) {
+ action.setSelection(event.getSelection());
+ }
+ }
}
/**
- * @param firstElement
+ * Class represents an BaseAction as SWT button control and runs action when
+ * button is prtessed
+ *
+ * @author eskimo
*/
- public void selectionChanged(SeamRuntime selection) {
- if(selection == null) {
- bar.setEnabled(REMOVE, false);
- bar.setEnabled(XChildrenEditor.EDIT, false);
- } else {
- bar.setEnabled(REMOVE, true);
- bar.setEnabled(XChildrenEditor.EDIT, true);
+ public static class ActionButton implements IPropertyChangeListener {
+
+ private static final int DEFAULT_WIDTH_HINT = 50;
+
+ private Button button;
+
+ private BaseAction action;
+
+ /**
+ * Create Button control with parent control and style that represents
+ * action
+ *
+ * @param parent
+ * Composite
+ * @param style
+ * int
+ * @param action
+ * BaseAction
+ */
+ public ActionButton(Composite parent, int style, BaseAction action) {
+ this.button = new Button(parent, style);
+ this.action = action;
+
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL,
+ GridData.CENTER, false, false);
+
+ gd.horizontalAlignment = GridData.FILL;
+ gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
+ gd.widthHint = DEFAULT_WIDTH_HINT;
+ this.button.setLayoutData(gd);
+ this.action.addPropertyChangeListener(this);
+ this.button.setText(action.getText());
+ this.button.setEnabled(action.isEnabled());
+ this.button.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+ ActionButton.this.action.run();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
}
- if(selection==null
- || selection == SeamRuntimeManager.getInstance().getDefaultRuntime()) {
- } else {
+
+ /**
+ * Return SWT button control that calls provided action
+ *
+ * @return Control - button swt control
+ */
+ public Control getControl() {
+ return button;
}
+
+ /**
+ * Update enabled/disabled button state
+ *
+ * @param event
+ * PropertyChangeEvent
+ * @see
org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event.getProperty().equals(IAction.ENABLED)) {
+ button.setEnabled(((Boolean) event.getNewValue())
+ .booleanValue());
+ }
+ }
}
/**
- * @see
org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
+ * Action that changes state enable/disable based on current table selection
+ *
+ * @author eskimo
*/
- public void widgetDefaultSelected(SelectionEvent e) {}
+ public abstract class BaseAction extends Action {
+ SeamRuntime[] runtimes = new SeamRuntime[0];
+
+ /**
+ * Constructor creates action with provided name
+ *
+ * @param name
+ * String - action name
+ */
+ public BaseAction(String name) {
+ super(name);
+ updateEnablement();
+ }
+
+ /**
+ * Set current selection
+ *
+ * @param selection
+ * ISelection - selected items
+ */
+ public void setSelection(ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ List<SeamRuntime> rts = new ArrayList<SeamRuntime>();
+ for (Object rt : ((IStructuredSelection) selection).toArray()) {
+ rts.add((SeamRuntime) rt);
+ }
+ runtimes = rts.toArray(new SeamRuntime[] {});
+ } else {
+ runtimes = new SeamRuntime[0];
+ }
+ updateEnablement();
+ }
+
+ protected abstract void updateEnablement();
+ }
+
/**
- * @see
org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ * Action that invokes New Seam Runtime Dialog
+ *
+ * @author eskimo
*/
- public void widgetSelected(SelectionEvent e) {
- }
-
- private void removeRuntime(SeamRuntime r) {
- boolean used = isRuntimeUsed(r.getName());
- String title = SeamUIMessages.RUNTIME_DELETE_CONFIRM_TITLE;
- String message = (used)
- ? NLS.bind(SeamUIMessages.RUNTIME_DELETE_USED_CONFIRM, r.getName())
- : NLS.bind(SeamUIMessages.RUNTIME_DELETE_NOT_USED_CONFIRM, r.getName());
- boolean b = MessageDialog.openConfirm(bar.getControl().getShell(), title, message);
- if(!b) return;
- if(changed.containsKey(r)) {
- r = changed.remove(r);
+ public class AddAction extends BaseAction {
+
+ static final String ACTION_NAME = "&Add";
+
+ /**
+ * Constructior create Add action with default name
+ */
+ public AddAction() {
+ super(ACTION_NAME);
+ // This action is always available
+ setEnabled(true);
}
- removed.add(r);
- if(added.contains(r)) {
- added.remove(r);
+
+ /**
+ * Do nothing, because Add action should be always available
+ */
+ @Override
+ protected void updateEnablement() {
+ // Add button is always available
}
- ((List)getValue()).remove(r);
- }
-
- private boolean isRuntimeUsed(String runtimeName) {
- IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- for (int i = 0; i < ps.length; i++) {
- ISeamProject sp = SeamCorePlugin.getSeamProject(ps[i], false);
- if(sp != null && runtimeName.equals(sp.getRuntimeName())) return true;
+
+ /**
+ * Invoke New Seam Runtime Dialog
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ Wizard wiz = new SeamRuntimeNewWizard(
+ (List<SeamRuntime>) getValue(), added);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent()
+ .getActiveShell(), wiz);
+ dialog.open();
+ tableView.refresh();
}
- return false;
}
- public void action(String command) {
- if(XChildrenEditor.ADD.equals(command)) {
- Wizard wiz = new SeamRuntimeNewWizard((List<SeamRuntime>)getValue(), added);
- WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wiz);
+ /**
+ * Action starts an editing selected Seam Runtime in Edit Seam Runtime
+ * dialog
+ *
+ * @author eskimo
+ */
+ public class EditAction extends BaseAction {
+
+ static final String ACTION_NAME = "&Edit";
+
+
+ /**
+ * Create EditAction with default name
+ *
+ * @param text
+ */
+ public EditAction() {
+ super(ACTION_NAME);
+ }
+
+ /**
+ * Edit action is enabled when the only Seam Runtime is selected
+ */
+ @Override
+ protected void updateEnablement() {
+ // available when the only SeamRuntime is selected
+ setEnabled(runtimes.length == 1);
+ }
+
+ /**
+ * Start editing selected Seam Runtime in Edit Seam Runtime Wizard
+ * Dialog
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ Wizard wiz = new SeamRuntimeEditWizard(
+ (List<SeamRuntime>) getValue(), runtimes[0], added, changed);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent()
+ .getActiveShell(), wiz);
dialog.open();
tableView.refresh();
- } else if(REMOVE.equals(command)) {
- ISelection s = tableView.getSelection();
- if(s == null || s.isEmpty() || !(s instanceof IStructuredSelection)) return;
- IStructuredSelection ss = (IStructuredSelection)s;
- Iterator<?> i = ss.iterator();
- while(i.hasNext()) {
- Object o = i.next();
- if(o instanceof SeamRuntime) {
- removeRuntime((SeamRuntime)o);
+ if (changed.containsValue(runtimes[0])) {
+ SeamRuntime c = findChangedRuntime(runtimes[0]);
+ if (c != null) {
+ tableView.setSelection(new StructuredSelection(c));
}
}
- tableView.refresh();
- } else if(XChildrenEditor.EDIT.equals(command)) {
- ISelection s = tableView.getSelection();
- if(s == null || s.isEmpty() || !(s instanceof IStructuredSelection)) return;
- IStructuredSelection ss = (IStructuredSelection)s;
- Iterator<?> i = ss.iterator();
- while(i.hasNext()) {
- Object o = i.next();
- if(o instanceof SeamRuntime) {
- Wizard wiz = new SeamRuntimeEditWizard((List<SeamRuntime>)getValue(),
(SeamRuntime)o, added, changed);
- WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(),
wiz);
- dialog.open();
- tableView.refresh();
- if(changed.containsValue(o)) {
- SeamRuntime c = findChangedRuntime((SeamRuntime)o);
- if(c != null) {
- tableView.setSelection(new StructuredSelection(c));
- }
- }
+ }
+
+ private SeamRuntime findChangedRuntime(SeamRuntime source) {
+ for (SeamRuntime r : changed.keySet()) {
+ if (source == changed.get(r)) {
+ return r;
}
}
+ return null;
}
}
-
- private SeamRuntime findChangedRuntime(SeamRuntime source) {
- for(SeamRuntime r: changed.keySet()) {
- if(source == changed.get(r)) return r;
+
+ /**
+ * Action deletes all selected Seam Runtimes. A worning message is shown for
+ * used Seam Runtimes
+ *
+ * @author eskimo
+ */
+ public class RemoveAction extends BaseAction {
+
+ static final String ACTION_NAME = "&Remove";
+ /**
+ * Create DeleteAction action with default name
+ */
+ public RemoveAction() {
+ super(ACTION_NAME);
}
- return null;
- }
-
- public void dispose() {
- bar.dispose();
- super.dispose();
- }
- protected void createCommandBar(Composite control) {
- //TODO insert EDIT command
- String[] commands = new String[]{XChildrenEditor.ADD, XChildrenEditor.EDIT, REMOVE};
- bar.setCommands(commands);
- bar.getLayout().direction = SWT.VERTICAL;
- bar.getLayout().buttonWidth = convertHorizontalDLUsToPixels(control,
IDialogConstants.BUTTON_WIDTH);
- setMargins(bar);
- bar.createControl(control);
- bar.getControl().setLayoutData(new GridData(GridData.FILL_VERTICAL));
+ @Override
+ protected void updateEnablement() {
+ setEnabled(runtimes.length > 0);
+ }
+
+ /**
+ * Remove all selected Seam Runtimes one by one
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ for (SeamRuntime rt : runtimes) {
+ removeRuntime(rt);
+ }
+ tableView.refresh();
+ }
+
+ private void removeRuntime(SeamRuntime r) {
+ boolean used = isRuntimeUsed(r.getName());
+ String title = SeamUIMessages.RUNTIME_DELETE_CONFIRM_TITLE;
+ String message = (used) ? NLS.bind(
+ SeamUIMessages.RUNTIME_DELETE_USED_CONFIRM, r.getName())
+ : NLS.bind(SeamUIMessages.RUNTIME_DELETE_NOT_USED_CONFIRM,
+ r.getName());
+ boolean b = MessageDialog.openConfirm(tableView.getControl()
+ .getShell(), title, message);
+ if (b) {
+ if (changed.containsKey(r)) {
+ r = changed.remove(r);
+ }
+ removed.add(r);
+ if (added.contains(r)) {
+ added.remove(r);
+ }
+ ((List) getValue()).remove(r);
+ }
+ }
+
+ private boolean isRuntimeUsed(String runtimeName) {
+ IProject[] ps = ResourcesPlugin.getWorkspace().getRoot()
+ .getProjects();
+ for (int i = 0; i < ps.length; i++) {
+ ISeamProject sp = SeamCorePlugin.getSeamProject(ps[i], false);
+ if (sp != null && runtimeName.equals(sp.getRuntimeName())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
-
- protected void setMargins(CommandBar bar) {
- bar.getLayout().setMargins(0,10,0,0);
- }
- protected int convertHorizontalDLUsToPixels(Control control, int dlus) {
- GC gc= new GC(control);
- gc.setFont(control.getFont());
- int averageWidth= gc.getFontMetrics().getAverageCharWidth();
- gc.dispose();
-
- double horizontalDialogUnitSize = averageWidth * 0.25;
-
- return (int)Math.round(dlus * horizontalDialogUnitSize);
- }
-
-}
+}
\ No newline at end of file