Author: scabanovich
Date: 2007-09-10 10:50:21 -0400 (Mon, 10 Sep 2007)
New Revision: 3507
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
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/CheckBoxFieldEditor.java
Log:
JBIDE-825 Added project property page Seam Settings.
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2007-09-10 14:47:50 UTC (rev
3506)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2007-09-10 14:50:21 UTC (rev
3507)
@@ -336,6 +336,15 @@
</adapt>
</enabledWhen>
</page>
+
+ <page
+ name="Seam Settings"
+
class="org.jboss.tools.seam.ui.preferences.SeamSettingsPreferencePage"
+
id="org.jboss.tools.seam.ui.propertyPages.SeamSettingsPreferencePage">
+ <enabledWhen>
+ <adapt type="org.eclipse.core.resources.IProject"/>
+ </enabledWhen>
+ </page>
</extension>
<extension
point="org.eclipse.ui.perspectives">
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-10
14:47:50 UTC (rev 3506)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencePage.java 2007-09-10
14:50:21 UTC (rev 3507)
@@ -47,6 +47,8 @@
*/
SeamRuntimeListFieldEditor seamRuntimes
= new SeamRuntimeListFieldEditor("rtlist","Runtime List",new
ArrayList<SeamRuntime>(Arrays.asList(SeamRuntimeManager.getInstance().getRuntimes())));
+
+ SeamRuntime initialDefault;
/**
*
@@ -77,6 +79,9 @@
GridLayout gl = new GridLayout(3,false);
root.setLayout(gl);
seamRuntimes.doFillIntoGrid(root);
+
+ initialDefault = SeamRuntimeManager.getInstance().getDefaultRuntime();
+
return root;
}
@@ -100,6 +105,9 @@
for (SeamRuntime rt : seamRuntimes.getAddedSeamRuntimes()) {
SeamRuntimeManager.getInstance().addRuntime(rt);
}
+ if(initialDefault != null && seamRuntimes.getDefaultSeamRuntime() !=
initialDefault) {
+ initialDefault.setDefault(false);
+ }
seamRuntimes.getDefaultSeamRuntime().setDefault(true);
SeamRuntimeManager.getInstance().save();
}
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java 2007-09-10
14:50:21 UTC (rev 3507)
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * 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.preferences;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+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.dialogs.PropertyPage;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+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.SeamGuiPlugin;
+import org.jboss.tools.seam.ui.widget.editor.IFieldEditor;
+import org.jboss.tools.seam.ui.widget.editor.SwtFieldEditorFactory;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class SeamSettingsPreferencePage extends PropertyPage {
+ IProject project;
+
+ IFieldEditor seamEnablement;
+ IFieldEditor runtime;
+
+ public SeamSettingsPreferencePage() {
+ }
+
+ public void setElement(IAdaptable element) {
+ super.setElement(element);
+ project = (IProject)getElement().getAdapter(IProject.class);
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, false);
+ boolean hasSeamSupport = seamProject != null;
+ seamEnablement = SwtFieldEditorFactory.INSTANCE.createCheckboxEditor("Seam
support", "Seam support", false);
+ seamEnablement.setValue(hasSeamSupport);
+
+ SeamRuntime[] rs = SeamRuntimeManager.getInstance().getRuntimes();
+ List<String> values = new ArrayList<String>();
+ String defaultValue = null;
+ for (int i = 0; i < rs.length; i++) {
+ values.add(rs[i].getName());
+ if(rs[i].isDefault()) defaultValue = rs[i].getName();
+ }
+ runtime = SwtFieldEditorFactory.INSTANCE.createComboEditor("Runtime",
"Runtime", values, defaultValue);
+
+ List<IFieldEditor> editorOrder = new ArrayList<IFieldEditor>();
+ editorOrder.add(seamEnablement);
+ editorOrder.add(runtime);
+
+ if(hasSeamSupport) {
+ SeamRuntime current = seamProject.getRuntime();
+ if(current != null) runtime.setValue(current.getName());
+ } else {
+ if(defaultValue != null) runtime.setValue(defaultValue);
+ }
+
+ seamEnablement.addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ Object value = evt.getNewValue();
+ if(value instanceof Boolean) {
+ boolean v = ((Boolean)value).booleanValue();
+ updateRuntimeEnablement(v);
+ validate();
+ }
+ }
+ });
+
+ runtime.addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ validate();
+ }
+ });
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ int columnNumber = 1;
+ for (IFieldEditor fieldEditor : editorOrder) {
+ if(fieldEditor.getNumberOfControls()>columnNumber)
+ columnNumber=fieldEditor.getNumberOfControls();
+ }
+ GridLayout gl = new GridLayout(columnNumber, false);
+ gl.verticalSpacing = 5;
+ gl.marginTop = 3;
+ gl.marginLeft = 3;
+ gl.marginRight = 3;
+ composite.setLayout(gl);
+ for (IFieldEditor fieldEditor2 : editorOrder) {
+ fieldEditor2.doFillIntoGrid(composite);
+ }
+
+ runtime.setEditable(false);
+ if(!hasSeamSupport) {
+ updateRuntimeEnablement(false);
+ }
+
+ return composite;
+ }
+
+ public boolean performOk() {
+ if(getSeamSupport()) {
+ addSeamSupport();
+ changeRuntime();
+ } else {
+ removeSeamSupport();
+ }
+ return true;
+ }
+
+ private void updateRuntimeEnablement(boolean enabled) {
+ Object[] cs = runtime.getEditorControls();
+ for (int i = 0; i < cs.length; i++) {
+ if(cs[i] instanceof Control) {
+ ((Control)cs[i]).setEnabled(enabled);
+ }
+ }
+ }
+
+ private void removeSeamSupport() {
+ try {
+ EclipseResourceUtil.removeNatureFromProject(project, ISeamProject.NATURE_ID);
+ } catch (CoreException e) {
+ SeamGuiPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ private void addSeamSupport() {
+ try {
+ EclipseResourceUtil.addNatureToProject(project, ISeamProject.NATURE_ID);
+ } catch (CoreException e) {
+ SeamGuiPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ private void changeRuntime() {
+ String name = getRuntimeName();
+ SeamRuntime r = SeamRuntimeManager.getInstance().findRuntimeByName(name);
+ if(r == null) return;
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, false);
+ seamProject.setRuntime(r);
+ }
+
+ private boolean getSeamSupport() {
+ Object o = seamEnablement.getValue();
+ return o instanceof Boolean && ((Boolean)o).booleanValue();
+ }
+
+ private String getRuntimeName() {
+ return runtime.getValueAsString();
+ }
+
+ private void validate() {
+ //TODO
+ }
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/CheckBoxFieldEditor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/CheckBoxFieldEditor.java 2007-09-10
14:47:50 UTC (rev 3506)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/CheckBoxFieldEditor.java 2007-09-10
14:50:21 UTC (rev 3507)
@@ -64,6 +64,9 @@
CheckBoxField checkBoxFild= new CheckBoxField(parent);
checkBoxFild.addPropertyChangeListener(this);
checkBoxControl = checkBoxFild.getCheckBox();
+ if(getValue() instanceof Boolean) {
+ checkBoxFild.getCheckBox().setSelection(((Boolean)getValue()).booleanValue());
+ }
} else if(parent!=null) {
Assert.isTrue(checkBoxControl.getParent()==parent);
}