Author: dgolovin
Date: 2007-09-07 06:03:06 -0400 (Fri, 07 Sep 2007)
New Revision: 3484
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamGuiPlugin.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/SeamInstallWizardPage.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/ValidatorFactory.java
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/IFieldEditorFactory.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SwtFieldEditorFactory.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/TaggedComboFieldEditor.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-825
Seam Runtimes lis added on seam preference page
Seam runtime selection added to seam facet wizard page
JUnit tests for SeamRuntime manager
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamGuiPlugin.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamGuiPlugin.java 2007-09-07
10:02:58 UTC (rev 3483)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamGuiPlugin.java 2007-09-07
10:03:06 UTC (rev 3484)
@@ -10,10 +10,25 @@
******************************************************************************/
package org.jboss.tools.seam.ui;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
+import org.eclipse.datatools.connectivity.ProfileManager;
+import org.eclipse.datatools.connectivity.db.generic.IDBConnectionProfileConstants;
+import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants;
+import org.eclipse.datatools.connectivity.drivers.DriverInstance;
+import org.eclipse.datatools.connectivity.drivers.DriverManager;
+import org.eclipse.datatools.connectivity.drivers.IDriverMgmtConstants;
+import org.eclipse.datatools.connectivity.drivers.IPropertySet;
+import org.eclipse.datatools.connectivity.drivers.PropertySetImpl;
+import org.eclipse.datatools.connectivity.drivers.models.OverrideTemplateDescriptor;
+import org.eclipse.datatools.connectivity.drivers.models.TemplateDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jboss.tools.common.log.BaseUIPlugin;
import org.jboss.tools.common.log.IPluginLog;
+import org.jboss.tools.seam.core.SeamPreferences;
+import org.jboss.tools.seam.core.project.facet.SeamFacetPreference;
import org.osgi.framework.BundleContext;
/**
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/SeamInstallWizardPage.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/SeamInstallWizardPage.java 2007-09-07
10:02:58 UTC (rev 3483)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/SeamInstallWizardPage.java 2007-09-07
10:03:06 UTC (rev 3484)
@@ -7,7 +7,7 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.seam.ui.internal.project.facet;
import java.beans.PropertyChangeEvent;
@@ -23,11 +23,11 @@
import org.eclipse.datatools.connectivity.ProfileManager;
import org.eclipse.datatools.connectivity.db.generic.IDBConnectionProfileConstants;
import org.eclipse.datatools.connectivity.db.generic.ui.NewConnectionProfileWizard;
-import org.eclipse.datatools.connectivity.ui.dse.dialogs.ProfileSelectionComposite;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jst.j2ee.project.facet.IJ2EEModuleFacetInstallDataModelProperties;
import org.eclipse.swt.SWT;
@@ -47,12 +47,16 @@
import org.hibernate.eclipse.console.utils.DriverClassHelpers;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.project.facet.SeamFacetPreference;
+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.widget.editor.ButtonFieldEditor;
import org.jboss.tools.seam.ui.widget.editor.CompositeEditor;
import org.jboss.tools.seam.ui.widget.editor.IFieldEditor;
import org.jboss.tools.seam.ui.widget.editor.IFieldEditorFactory;
import org.jboss.tools.seam.ui.widget.editor.ITaggedFieldEditor;
+import
org.jboss.tools.seam.ui.widget.editor.SeamRuntimeListFieldEditor.SeamRuntimeNewWizard;
import org.jboss.tools.seam.ui.wizard.SeamFormWizard;
/**
@@ -61,12 +65,13 @@
*/
public class SeamInstallWizardPage extends AbstractFacetWizardPage implements
IFacetWizardPage, IDataModelListener {
-
+
public static final String PAGE_DESCRIPTION = "Configure Seam Facet
Settings";
/**
- *
+ *
*/
- boolean seamHomeRequiresSave =
SeamFacetPreference.getStringPreference(SeamFacetPreference.SEAM_HOME_FOLDER).equals("");
+ boolean seamHomeRequiresSave = SeamFacetPreference.getStringPreference(
+ SeamFacetPreference.SEAM_HOME_FOLDER).equals("");
/**
*
*/
@@ -81,13 +86,17 @@
*
*/
DataModelValidatorDelegate validatorDelegate;
-
+
IFieldEditor jBossSeamHomeEditor = IFieldEditorFactory.INSTANCE
- .createBrowseFolderEditor(
- ISeamFacetDataModelProperties.JBOSS_SEAM_HOME,
- "JBoss Seam Home Folder:",
- SeamFacetPreference
- .getStringPreference(SeamFacetPreference.SEAM_HOME_FOLDER));
+ .createComboWithButton(ISeamFacetDataModelProperties.JBOSS_SEAM_HOME,
+ "Seam Runtime", getRuntimeNames(),
SeamRuntimeManager.getInstance().getDefaultRuntime().getName(), true, new
NewSeamRuntimeAction(), (IValidator)null);
+
+// IFieldEditor jBossSeamHomeEditor = IFieldEditorFactory.INSTANCE
+// .createBrowseFolderEditor(
+// ISeamFacetDataModelProperties.JBOSS_SEAM_HOME,
+// "JBoss Seam Home Folder:",
+// SeamFacetPreference
+// .getStringPreference(SeamFacetPreference.SEAM_HOME_FOLDER));
IFieldEditor jBossAsDeployAsEditor = IFieldEditorFactory.INSTANCE
.createComboEditor(
ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,
@@ -100,9 +109,10 @@
IFieldEditor connProfileSelEditor = IFieldEditorFactory.INSTANCE
.createComboWithTwoButtons(
ISeamFacetDataModelProperties.SEAM_CONNECTION_PROFILE,
- "Connection profile:", getProfileNameList(),
SeamCorePlugin.getDefault().getPluginPreferences().getString(
- SeamFacetPreference.SEAM_DEFAULT_CONNECTION_PROFILE), true,
- new EditConnectionProfileAction(),
+ "Connection profile:",
+ getProfileNameList(),
+ "DefaultDS",
+ true, new EditConnectionProfileAction(),
new NewConnectionProfileAction(),
ValidatorFactory.NO_ERRORS_VALIDATOR);
IFieldEditor jBossAsDbTypeEditor = IFieldEditorFactory.INSTANCE
@@ -173,8 +183,7 @@
IFieldEditor testsPkgNameditor = IFieldEditorFactory.INSTANCE
.createTextEditor(
ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME,
- "Test Package Name:",
- "com.mydomain.projectname.test");
+ "Test Package Name:", "com.mydomain.projectname.test");
/**
*
@@ -210,24 +219,27 @@
}
/**
- * Finish has been pressed.
+ * Finish has been pressed.
*/
public void transferStateToConfig() {
- if( seamHomeRequiresSave) {
+ if (seamHomeRequiresSave) {
SeamCorePlugin.getDefault().getPluginPreferences().setValue(
- SeamFacetPreference.SEAM_HOME_FOLDER, jBossSeamHomeEditor.getValueAsString());
+ SeamFacetPreference.SEAM_HOME_FOLDER,
+ jBossSeamHomeEditor.getValueAsString());
}
- if("".equals(SeamCorePlugin.getDefault().getPluginPreferences().getString((
- SeamFacetPreference.SEAM_DEFAULT_CONNECTION_PROFILE)))) {
+ if ("".equals(SeamCorePlugin.getDefault().getPluginPreferences()
+ .getString(
+ (SeamFacetPreference.SEAM_DEFAULT_CONNECTION_PROFILE)))) {
SeamCorePlugin.getDefault().getPluginPreferences().setValue(
- SeamFacetPreference.SEAM_DEFAULT_CONNECTION_PROFILE,
connProfileSelEditor.getValueAsString());
+ SeamFacetPreference.SEAM_DEFAULT_CONNECTION_PROFILE,
+ connProfileSelEditor.getValueAsString());
}
}
-
/**
* Registers editor in data synchronizer and put SWT controls for it at
* wizard page.
+ *
* @param editor
* @param parent
* @param columns
@@ -238,6 +250,15 @@
editor.doFillIntoGrid(parent);
}
+ public List<String> getRuntimeNames() {
+ SeamRuntime[] rts =
SeamRuntimeManager.getInstance().getRuntimes(SeamVersion.SEAM_1_2);
+ List<String> result = new ArrayList<String>();
+ for(SeamRuntime seamRuntime : rts) {
+ result.add(seamRuntime.getName());
+ }
+ return result;
+ }
+
/**
* Creates Seam Facet Wizard Page contents
*/
@@ -300,36 +321,35 @@
setControl(root);
NewProjectDataModelFacetWizard wizard = (NewProjectDataModelFacetWizard) getWizard();
-
+
IDataModel model = wizard.getDataModel();
- if(validatorDelegate==null) {
+ if (validatorDelegate == null) {
validatorDelegate = new DataModelValidatorDelegate(this.model, this);
- validatorDelegate.addValidatorForProperty(
- jBossSeamHomeEditor.getName(),
- ValidatorFactory.JBOSS_SEAM_HOME_FOLDER_VALIDATOR);
- validatorDelegate
- .addValidatorForProperty(connProfileSelEditor.getName(),
- ValidatorFactory.CONNECTION_PROFILE_IS_NOT_SELECTED);
- validatorDelegate
- .addValidatorForProperty(testsPkgNameditor.getName(),
- new PackageNameValidator(
- testsPkgNameditor.getName(), "tests"));
- validatorDelegate
- .addValidatorForProperty(entityBeanPkgNameditor.getName(),
- new PackageNameValidator(
- entityBeanPkgNameditor.getName(), "entity beans"));
- validatorDelegate
- .addValidatorForProperty(sessionBeanPkgNameditor.getName(),
- new PackageNameValidator(
- sessionBeanPkgNameditor.getName(), "session beans"));
- }
-
- jBossAsDbTypeEditor.addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- jBossHibernateDialectEditor.setValue(HIBERNATE_HELPER.getDialectClass(evt.getNewValue().toString()));
- }
- });
+ validatorDelegate.addValidatorForProperty(jBossSeamHomeEditor
+ .getName(),
+ ValidatorFactory.JBOSS_SEAM_HOME_IS_NOT_SELECTED);
+ validatorDelegate.addValidatorForProperty(connProfileSelEditor
+ .getName(),
+ ValidatorFactory.CONNECTION_PROFILE_IS_NOT_SELECTED);
+ validatorDelegate.addValidatorForProperty(testsPkgNameditor
+ .getName(), new PackageNameValidator(testsPkgNameditor
+ .getName(), "tests"));
+ validatorDelegate.addValidatorForProperty(entityBeanPkgNameditor
+ .getName(), new PackageNameValidator(entityBeanPkgNameditor
+ .getName(), "entity beans"));
+ validatorDelegate.addValidatorForProperty(sessionBeanPkgNameditor
+ .getName(), new PackageNameValidator(
+ sessionBeanPkgNameditor.getName(), "session beans"));
+ }
+
+ jBossAsDbTypeEditor
+ .addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ jBossHibernateDialectEditor.setValue(HIBERNATE_HELPER
+ .getDialectClass(evt.getNewValue().toString()));
+ }
+ });
}
/**
@@ -350,7 +370,7 @@
public static final String GENERIC_JDBC_PROVIDER_ID
= "org.eclipse.datatools.connectivity.db.generic.connectionProfile";
-
+
/*
*
*/
@@ -458,7 +478,9 @@
}
}
}
+
+
/**
* It is overridden to fill Code Generation group with the default package
* names
@@ -466,30 +488,33 @@
@Override
public void setVisible(boolean visible) {
sessionBeanPkgNameditor
- .setValue("org.domain."
- + model.getProperty(IFacetDataModelProperties.FACET_PROJECT_NAME)
- + ".session");
+ .setValue("org.domain."
+ + model
+ .getProperty(IFacetDataModelProperties.FACET_PROJECT_NAME)
+ + ".session");
entityBeanPkgNameditor
- .setValue("org.domain."
- + model.getProperty(IFacetDataModelProperties.FACET_PROJECT_NAME)
- + ".entity");
+ .setValue("org.domain."
+ + model
+ .getProperty(IFacetDataModelProperties.FACET_PROJECT_NAME)
+ + ".entity");
testsPkgNameditor
- .setValue("org.domain."
- + model.getProperty(IFacetDataModelProperties.FACET_PROJECT_NAME)
- + ".test");
- if(visible) {
+ .setValue("org.domain."
+ + model
+ .getProperty(IFacetDataModelProperties.FACET_PROJECT_NAME)
+ + ".test");
+ if (visible) {
String message = validatorDelegate.getFirstValidationError();
- this.setPageComplete(message==null);
+ this.setPageComplete(message == null);
this.setMessage(message);
}
super.setVisible(visible);
};
-
+
public class PackageNameValidator implements IValidator {
String fieldName;
String targetName;
-
+
/**
* @param fieldName
* @param targetName
@@ -498,19 +523,47 @@
this.fieldName = fieldName;
this.targetName = targetName;
}
-
+
/**
* @see IValidator#validate(Object, Object)
*/
public Map<String, String> validate(Object value, Object context) {
- IStatus status = JavaConventions.validatePackageName(
- value.toString(),
- CompilerOptions.VERSION_1_5,
- CompilerOptions.VERSION_1_5);
- if(!status.isOK()) {
- return ValidatorFactory.createErrormessage(fieldName, "Package name for " +
targetName + " is not valid" );
+ IStatus status = JavaConventions.validatePackageName(value
+ .toString(), CompilerOptions.VERSION_1_5,
+ CompilerOptions.VERSION_1_5);
+ if (!status.isOK()) {
+ return ValidatorFactory.createErrormessage(fieldName,
+ "Package name for " + targetName + " is not valid");
}
return ValidatorFactory.NO_ERRORS;
}
}
+
+ public class NewSeamRuntimeAction extends
+ ButtonFieldEditor.ButtonPressedAction {
+ /**
+ * @param label
+ */
+ public NewSeamRuntimeAction() {
+ super("Add");
+ }
+
+ public void run() {
+ List<SeamRuntime> added = new ArrayList<SeamRuntime>();
+ Wizard wiz = new SeamRuntimeNewWizard((List<SeamRuntime>)
+ new
ArrayList<SeamRuntime>(Arrays.asList(SeamRuntimeManager.getInstance().getRuntimes()))
+ ,added);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wiz);
+ dialog.open();
+
+
+ if (added.size()>0) {
+ SeamRuntimeManager.getInstance().addRuntime(added.get(0));
+ getFieldEditor().setValue(added.get(0).getName());
+ ((ITaggedFieldEditor) ((CompositeEditor) jBossSeamHomeEditor)
+ .getEditors().get(1)).setTags(getRuntimeNames()
+ .toArray(new String[0]));
+ }
+ }
+ }
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/ValidatorFactory.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/ValidatorFactory.java 2007-09-07
10:02:58 UTC (rev 3483)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/internal/project/facet/ValidatorFactory.java 2007-09-07
10:03:06 UTC (rev 3484)
@@ -125,7 +125,6 @@
+ "' points to file");
return NO_ERRORS;
}
-
};
/**
@@ -144,7 +143,6 @@
if (!new File(value.toString(), "seam").isFile()) {
errors = createErrormessage("Seam Home Folde field points to " +
"location that doesn't look like seam home folder");
-
}
return errors;
}
@@ -332,6 +330,17 @@
}
};
+ public static IValidator JBOSS_SEAM_HOME_IS_NOT_SELECTED = new IValidator() {
+ public Map<String, String> validate(Object value, Object context) {
+ if (value == null || "".equals(value.toString().trim())) {
+ return createErrormessage(
+ ISeamFacetDataModelProperties.JBOSS_SEAM_HOME,
+ "Seam Runtime is not selected");
+ }
+ return NO_ERRORS;
+ }
+ };
+
public static CompilationUnit createCompilationUnit(String classDecl,
IProject project) {
ASTParser parser = ASTParser.newParser(AST.JLS3);
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-09-07
10:02:58 UTC (rev 3483)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencePage.java 2007-09-07
10:03:06 UTC (rev 3484)
@@ -13,6 +13,8 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Map;
import org.eclipse.jface.dialogs.IMessageProvider;
@@ -20,16 +22,17 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
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.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.project.facet.SeamFacetPreference;
-import org.jboss.tools.seam.ui.internal.project.facet.IValidator;
+import org.jboss.tools.seam.core.project.facet.SeamRuntime;
+import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
import org.jboss.tools.seam.ui.internal.project.facet.ValidatorFactory;
import org.jboss.tools.seam.ui.widget.editor.IFieldEditor;
+import org.jboss.tools.seam.ui.widget.editor.SeamRuntimeListFieldEditor;
import org.jboss.tools.seam.ui.widget.editor.SwtFieldEditorFactory;
/**
@@ -42,11 +45,9 @@
/**
*
*/
- IFieldEditor editor
- = SwtFieldEditorFactory.INSTANCE.createBrowseFolderEditor(
- "seam.home.folder", "Seam Home Folder:",
- SeamFacetPreference.getStringPreference(SeamFacetPreference.SEAM_HOME_FOLDER));
-
+ SeamRuntimeListFieldEditor seamRuntimes
+ = new SeamRuntimeListFieldEditor("rtlist","Runtime List",new
ArrayList<SeamRuntime>(Arrays.asList(SeamRuntimeManager.getInstance().getRuntimes())));
+
/**
*
*/
@@ -75,8 +76,7 @@
Composite root = new Composite(parent, SWT.NONE);
GridLayout gl = new GridLayout(3,false);
root.setLayout(gl);
- editor.doFillIntoGrid(root);
- editor.addPropertyChangeListener(this);
+ seamRuntimes.doFillIntoGrid(root);
return root;
}
@@ -90,15 +90,6 @@
*
*/
public void propertyChange(PropertyChangeEvent arg0) {
- Map errors
- = ValidatorFactory.JBOSS_SEAM_HOME_FOLDER_VALIDATOR.validate(editor.getValue(),
null);
- if(errors.size()>0) {
- setValid(false);
- setMessage(errors.get(errors.keySet().iterator().next()).toString(),
IMessageProvider.ERROR);
- } else {
- setMessage(null);
- setValid(true);
- }
}
/**
@@ -106,8 +97,11 @@
*/
@Override
protected void performApply() {
- SeamCorePlugin.getDefault().getPluginPreferences().setValue(
- SeamFacetPreference.SEAM_HOME_FOLDER, editor.getValueAsString());
+ for (SeamRuntime rt : seamRuntimes.getAddedSeamRuntimes()) {
+ SeamRuntimeManager.getInstance().addRuntime(rt);
+ }
+ seamRuntimes.getDefaultSeamRuntime().setDefault(true);
+ SeamRuntimeManager.getInstance().save();
}
/**
@@ -115,11 +109,6 @@
*/
@Override
protected void performDefaults() {
- editor.removePropertyChangeListener(this);
- editor.setValue(
- SeamCorePlugin.getDefault().getPluginPreferences().getDefaultString(
- SeamFacetPreference.SEAM_HOME_FOLDER));
- editor.addPropertyChangeListener(this);
setValid(true);
setMessage(null);
performApply();
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-09-07
10:02:58 UTC (rev 3483)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/IFieldEditorFactory.java 2007-09-07
10:03:06 UTC (rev 3484)
@@ -13,6 +13,7 @@
import java.util.List;
import org.jboss.tools.seam.ui.internal.project.facet.IValidator;
+import org.jboss.tools.seam.ui.widget.editor.ButtonFieldEditor.ButtonPressedAction;
public interface IFieldEditorFactory {
@@ -123,4 +124,9 @@
ButtonFieldEditor.ButtonPressedAction action2, IValidator validator);
public ButtonFieldEditor.ButtonPressedAction createNotImplementedYetAction(String
buttonName);
+
+ public IFieldEditor createComboWithButton(String name, String label,
+ List values, Object defaultValue, boolean flat,
+ ButtonPressedAction action1,
+ IValidator validator);
}
Added:
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
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java 2007-09-07
10:03:06 UTC (rev 3484)
@@ -0,0 +1,451 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+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.Shell;
+import org.eclipse.swt.widgets.TableColumn;
+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.internal.project.facet.ValidatorFactory;
+import org.jboss.tools.seam.ui.wizard.SeamFormWizard;
+
+/**
+ * @author eskimo
+ *
+ */
+public class SeamRuntimeListFieldEditor extends BaseFieldEditor {
+
+ CheckboxTableViewer tableView = null;
+ Composite root = null;
+ /**
+ * @param name
+ * @param label
+ * @param defaultValue
+ */
+ public SeamRuntimeListFieldEditor(String name, String label, Object defaultValue) {
+ super(name, label, defaultValue);
+
+ }
+
+ private SeamRuntime checkedElement = null;
+
+ /**
+ *
+ * @return
+ */
+ public SeamRuntime getDefaultSeamRuntime() {
+ return checkedElement;
+ }
+
+ private List<SeamRuntime> added = new ArrayList<SeamRuntime>();
+
+ /**
+ *
+ * @return
+ */
+ public List<SeamRuntime> getAddedSeamRuntimes() {
+ return added;
+ }
+
+ private Map<SeamRuntime,SeamRuntime> changed = new
HashMap<SeamRuntime,SeamRuntime>();
+
+ /**
+ *
+ * @return
+ */
+ public Map<SeamRuntime,SeamRuntime> getChangedSeamRuntimes() {
+ return changed;
+ }
+
+ private List<SeamRuntime> removed = new ArrayList<SeamRuntime>();
+
+ /**
+ *
+ * @return
+ */
+ public List<SeamRuntime> getRemoved() {
+ return removed;
+ }
+
+ @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((Composite) root,
+ SWT.V_SCROLL|SWT.BORDER|SWT.FULL_SELECTION|SWT.SINGLE);
+
+ gd = new GridData();
+ gd.heightHint = 200;
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = true;
+
+ tableView.getControl().setLayoutData(gd);
+
+ Composite buttons = new Composite(root,SWT.NONE);
+ buttons.setLayout(new GridLayout(1,false));
+ gd = new GridData();
+ gd.horizontalAlignment = GridData.FILL;
+ gd.verticalAlignment = GridData.FILL;
+ gd.grabExcessVerticalSpace = true;
+ buttons.setLayoutData(gd);
+
+ final Button addBtn = new Button(buttons,SWT.PUSH);
+ addBtn.setText("Add");
+ gd = new GridData(GridData.FILL_HORIZONTAL,GridData.CENTER,false,false);
+ gd.horizontalAlignment = GridData.FILL;
+ gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
+ gd.widthHint = 50;
+
+ addBtn.setLayoutData(gd);
+ addBtn.addSelectionListener(new SelectionListener() {
+ /* (non-Javadoc)
+ * @see
org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+
+ Wizard wiz = new SeamRuntimeNewWizard((List<SeamRuntime>)getValue(), added);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wiz);
+ dialog.open();
+ tableView.refresh();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ /*final Button rmBtn = new Button(buttons,SWT.PUSH);
+ rmBtn.setText("Remove");
+ gd = new GridData(GridData.FILL_HORIZONTAL,GridData.CENTER,false,false);
+ gd.horizontalAlignment = GridData.FILL;
+ gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
+ rmBtn.setLayoutData(gd);
+
+ final Button editBtn = new Button(buttons,SWT.PUSH);
+ editBtn.setText("Edit");
+ gd = new GridData(GridData.FILL_HORIZONTAL,GridData.CENTER,false,false);
+ gd.horizontalAlignment = GridData.FILL;
+ gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
+ editBtn.setLayoutData(gd);*/
+
+ TableColumn tc1 = new TableColumn(tableView.getTable(),SWT.CENTER);
+ tc1.setWidth(21);
+ tc1.setResizable(false);
+
+ TableColumn tc2 = new TableColumn(tableView.getTable(),SWT.LEFT);
+ tc2.setWidth(100);
+ tc2.setText("Name");
+
+ TableColumn tc3 = new TableColumn(tableView.getTable(),SWT.LEFT);
+ tc3.setWidth(50);
+ tc3.setText("Version");
+
+ TableColumn tc4 = new TableColumn(tableView.getTable(),SWT.LEFT);
+ tc4.setWidth(100);
+ tc4.setText("Path");
+
+ tableView.setContentProvider(new IStructuredContentProvider() {
+
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof List)
+ return ((List<SeamRuntime>)inputElement).toArray();
+ else
+ throw new IllegalArgumentException("inputElement must be " +
+ "n instance of List<SeamRuntime>.");
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ viewer.refresh();
+ }
+ });
+
+ tableView.setLabelProvider(new ITableLabelProvider() {
+
+ public void addListener(ILabelProviderListener listener) {}
+
+ public void dispose() { }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ 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 "";
+ if(columnIndex==1) return rt.getName();
+ if(columnIndex==2) return rt.getVersion().toString();
+ if(columnIndex==3) return rt.getHomeDir();
+ return "";
+ }
+ });
+
+ tableView.setInput(getValue());
+ tableView.getTable().setLinesVisible(true);
+ tableView.getTable().setHeaderVisible(true);
+ 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()});
+ }
+ pcs.firePropertyChange(getName(), null, getValue());
+ }
+ });
+
+ for (SeamRuntime rt : (List<SeamRuntime>) getValue()) {
+ if(rt.isDefault()) {
+ tableView.setCheckedElements(new Object[]{rt});
+ checkedElement = rt;
+ break;
+ }
+ }
+
+ return new Control[]{tableView.getControl()};
+ }
+
+ @Override
+ public Object[] getEditorControls() {
+ return new Control[]{root};
+ }
+
+ @Override
+ public int getNumberOfControls() {
+ return 1;
+ }
+
+ public static void main (String [] args) {
+ Display display = new Display ();
+ Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout());
+ SeamRuntime rt = new SeamRuntime();
+ rt.setName("rtName1");
+ rt.setDefault(true);
+ rt.setHomeDir("/home");
+ rt.setVersion(SeamVersion.SEAM_1_2);
+ SeamRuntime rt2 = new SeamRuntime();
+ rt2.setName("rtName2");
+ rt2.setDefault(false);
+ rt2.setHomeDir("/home1");
+ rt2.setVersion(SeamVersion.SEAM_2_0);
+ List<SeamRuntime> rts = Arrays.asList(new SeamRuntime[]{rt,rt2});
+
+
+ new
SeamRuntimeListFieldEditor("name","label",rts).doFillIntoGrid(shell);
+
+ shell.open ();
+ while (!shell.isDisposed ()) {
+ if (!display.readAndDispatch ()) display.sleep ();
+ }
+ display.dispose ();
+ }
+
+ /**
+ *
+ * @param parent
+ */
+ public void doFillIntoGrid(Object parent) {
+ Assert.isTrue(parent instanceof Composite,
+ "Parent control should be Composite");
+ Assert.isTrue(((Composite)parent).getLayout()
+ instanceof GridLayout,"Editor supports only grid layout");
+ Composite aComposite = (Composite) parent;
+ 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);
+ }
+
+ public static class SeamRuntimeWizardPage extends WizardPage implements
PropertyChangeListener {
+
+ List<SeamRuntime> value = null;
+
+ IFieldEditor name = SwtFieldEditorFactory.INSTANCE.createTextEditor(
+ "name", "Name:", "");
+
+ IFieldEditor version = SwtFieldEditorFactory.INSTANCE.createComboEditor(
+ "version", "Version:", Arrays.asList(
+ new Object[]{SeamVersion.SEAM_1_2.toString()}),
+ SeamVersion.SEAM_1_2.toString(), true);
+
+ IFieldEditor homeDir = SwtFieldEditorFactory.INSTANCE.createBrowseFolderEditor(
+ "homeDir", "Home Folder:", "");
+
+ IFieldEditor dflt = SwtFieldEditorFactory.INSTANCE.createCheckboxEditor(
+ "default", "Use as default:", false);
+
+ /**
+ * @param parent
+ * @param style
+ */
+ public SeamRuntimeWizardPage(List<SeamRuntime> editedList) {
+ super("New Seam Runtime");
+ setMessage("Create a Seam Runtime");
+ setTitle("Seam Runtime");
+ setImageDescriptor(ImageDescriptor.createFromFile(
+ SeamFormWizard.class, "SeamWebProjectWizBan.png"));
+ value = editedList;
+ }
+ /**
+ *
+ */
+ public void createControl(Composite parent) {
+ parent.setLayout(new GridLayout(1, 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);
+ root.setLayout(gl);
+ name.doFillIntoGrid(root);
+ name.addPropertyChangeListener(this);
+ version.doFillIntoGrid(root);
+ version.addPropertyChangeListener(this);
+ homeDir.doFillIntoGrid(root);
+ homeDir.addPropertyChangeListener(this);
+ setPageComplete(false);
+ setControl(root);
+ }
+
+ /**
+ *
+ */
+ public void propertyChange(PropertyChangeEvent evt) {
+
+ if(name.getValueAsString()==null || "".equals(
+ name.getValueAsString().toString().trim())) {
+ setErrorMessage("Name cannot be empty");
+ setPageComplete(false);
+ return;
+ }
+
+ if(!name.getValueAsString().matches("[a-zA-Z_][a-zA-Z0-9_\\-\\.]*")) {
+ setErrorMessage("Runtime name is not correct");
+ setPageComplete(false);
+ return;
+ }
+ for (SeamRuntime rt : value) {
+ if(rt.getName().equals(name.getValueAsString())) {
+ setErrorMessage("Runtime '"+name.getValueAsString()+ "'
already exists");
+ setPageComplete(false);
+ return;
+ }
+ }
+
+ if(homeDir.getValueAsString()==null ||
"".equals(homeDir.getValueAsString().trim())) {
+ setErrorMessage("Path to seam home directory cannot be empty");
+ setPageComplete(false);
+ return;
+ }
+
+ Map errors = ValidatorFactory.JBOSS_SEAM_HOME_FOLDER_VALIDATOR.validate(
+ homeDir.getValueAsString(), null);
+ if( errors != ValidatorFactory.NO_ERRORS) {
+ setErrorMessage(errors.get(ISeamFacetDataModelProperties.JBOSS_SEAM_HOME).toString());
+ setPageComplete(false);
+ return;
+ }
+
+ setErrorMessage(null);
+ setPageComplete(true);
+ }
+
+ /**
+ *
+ * @return
+ */
+ public SeamRuntime getRuntime() {
+ SeamRuntime newRt = new SeamRuntime();
+ newRt.setName(name.getValueAsString());
+ newRt.setVersion(SeamVersion.parseFromString(version.getValueAsString()));
+ newRt.setHomeDir(homeDir.getValueAsString());
+ //newRt.setDefault((Boolean)dflt.getValue());
+ return newRt;
+ }
+ }
+
+ 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) {
+ super();
+ setWindowTitle("New Seam Runtime");
+ page1 = new SeamRuntimeWizardPage(value);
+ addPage(page1);
+ this.value = value;
+ this.added = added;
+ }
+
+ public boolean performFinish() {
+ added.add(page1.getRuntime());
+ value.add(page1.getRuntime());
+ return true;
+ }
+ }
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SwtFieldEditorFactory.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SwtFieldEditorFactory.java 2007-09-07
10:02:58 UTC (rev 3483)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SwtFieldEditorFactory.java 2007-09-07
10:03:06 UTC (rev 3484)
@@ -17,13 +17,16 @@
import org.eclipse.datatools.connectivity.db.generic.IDBConnectionProfileConstants;
import org.eclipse.datatools.connectivity.db.generic.ui.NewConnectionProfileWizard;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.project.facet.SeamRuntime;
import org.jboss.tools.seam.ui.internal.project.facet.IValidator;
import org.jboss.tools.seam.ui.widget.editor.ButtonFieldEditor.ButtonPressedAction;
+import
org.jboss.tools.seam.ui.widget.editor.SeamRuntimeListFieldEditor.SeamRuntimeNewWizard;
/**
*
@@ -154,7 +157,9 @@
};
}
-
+ /**
+ *
+ */
public ButtonFieldEditor.ButtonPressedAction createNotImplementedYetAction(String
buttonName) {
return new ButtonFieldEditor.ButtonPressedAction(buttonName) {
@Override
@@ -183,4 +188,20 @@
return editor;
}
+
+ /**
+ *
+ */
+ public IFieldEditor createComboWithButton(String name, String label,
+ List values, Object defaultValue, boolean flat,
+ ButtonPressedAction action1,
+ IValidator validator) {
+ CompositeEditor editor = new CompositeEditor(name,label,defaultValue);
+ editor.addFieldEditors(new IFieldEditor[]{
+ new LabelFieldEditor(name,label),
+ new ComboFieldEditor(name,label, values, defaultValue, false),
+ new ButtonFieldEditor(name, action1, defaultValue)
+ });
+ return editor;
+ }
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/TaggedComboFieldEditor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/TaggedComboFieldEditor.java 2007-09-07
10:02:58 UTC (rev 3483)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/TaggedComboFieldEditor.java 2007-09-07
10:03:06 UTC (rev 3484)
@@ -16,20 +16,27 @@
import org.eclipse.swt.widgets.Combo;
+/**
+ *
+ */
public class TaggedComboFieldEditor extends CompositeEditor implements
ITaggedFieldEditor, PropertyChangeListener{
List values = null;
boolean floatStyle = true;
+
ComboFieldEditor combo = null;
- public TaggedComboFieldEditor(String name, String label, List values, Object
defaultValue, boolean floatStyle) {
+ public TaggedComboFieldEditor(String name, String label, List values,
+ Object defaultValue, boolean floatStyle) {
+
super(name, label, defaultValue);
this.values = Collections.unmodifiableList(values);
this.floatStyle = floatStyle;
- combo = new ComboFieldEditor(name,label,values,defaultValue.toString(),floatStyle);
+ combo = new ComboFieldEditor(
+ name,label,values,defaultValue.toString(),floatStyle);
addFieldEditors(new IFieldEditor[]{new LabelFieldEditor(name,label),
- combo});
+ combo});
}
/* (non-Javadoc)