Author: Grid.Qian
Date: 2008-06-05 02:46:49 -0400 (Thu, 05 Jun 2008)
New Revision: 8556
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/BaseField.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/BaseFieldEditor.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/ButtonFieldEditor.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/CompositeEditor.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/IFieldEditor.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/INamedElement.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntime.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimeListConverter.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimeManager.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage2.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/LabelFieldEditor.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/PushButtonField.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/TextField.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/TextFieldEditor.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/MergeWebXMLCommand.java
trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUI.properties
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUIMessages.java
Log:
JBIDE-2261: implement define multi jbossws runtime
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/MergeWebXMLCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/MergeWebXMLCommand.java 2008-06-04
21:01:55 UTC (rev 8555)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/MergeWebXMLCommand.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -101,7 +101,7 @@
org.eclipse.jst.j2ee.webapplication.WebApp webapp) {
List theServlets = webapp.getServlets();
for (int i = 0; i < theServlets.size(); i++) {
- Servlet aServlet = (Servlet) theServlets.get(i);
+ org.eclipse.jst.j2ee.webapplication.Servlet aServlet =
(org.eclipse.jst.j2ee.webapplication.Servlet) theServlets.get(i);
if (aServlet.getServletName().equals(servletDescriptor._name)) {
return;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF 2008-06-04 21:01:55 UTC
(rev 8555)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF 2008-06-05 06:46:49 UTC
(rev 8556)
@@ -8,7 +8,9 @@
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
- org.jboss.tools.ws.core
+ org.jboss.tools.ws.core,
+ org.eclipse.ui.ide,
+ org.eclipse.wst.common.project.facet.core
Eclipse-LazyStart: true
Export-Package: org.jboss.tools.ws.ui,
org.jboss.tools.ws.ui.preferences
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUI.properties
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUI.properties 2008-06-04
21:01:55 UTC (rev 8555)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUI.properties 2008-06-05
06:46:49 UTC (rev 8556)
@@ -38,4 +38,32 @@
WAR_STATUS_LOCATION_FILE=war.properties
COMMOND=wsconsume.sh
-BIN=bin
\ No newline at end of file
+BIN=bin
+
+JBOSSWS_BASIC_EDITOR_COMPOSITE=Parent control should be Composite
+JBOSSWS_BASIC_EDITOR_SUPPORT=Editor supports only grid layout
+JBOSSWS_BASE_EDITOR_DIFFERENT=Parent for label is different
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NAME=Name
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_PATH=Path
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_INPUTELEMENT_MUST_BE=inputElement must be
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_AN_INSTANCEOF_OF_LIST=an instance of
List<JBossWSRuntime>.
+JBOSSWS_RUNTIME_DELETE_CONFIRM_TITLE=Confirm Runtime Delete
+JBOSSWS_RUNTIME_DELETE_USED_CONFIRM=Runtime ''{0}'' is used by JBossWS
projects. Are you sure you want to delete it?
+JBOSSWS_RUNTIME_DELETE_NOT_USED_CONFIRM=Are you sure you want to delete runtime
''{0}''?
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_EDIT_RUNTIME=Edit JBossWS Runtime
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_MODIFY_RUNTIME=Input new values
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NEW_RUNTIME=New JBossWS Runtime
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_PATH_TO_HOME_DIRECTORY_CANNOT_BE_EMPTY=Path to JBossWS
home directory cannot be empty
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_ALREADY_EXISTS=' already exists
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_RUNTIME=JBossWS Runtime
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_RUNTIME_NAME_IS_NOT_CORRECT=Runtime name is not
correct
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NAME_CANNOT_BE_EMPTY=Name cannot be empty
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_CREATE_A_RUNTIME=Create a JBossWS Runtime
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_HOME_FOLDER=Home Folder:
+JBOSSWS_COMPOSITE_EDITOR_THIS_METOD_CAN_BE_INVOKED=This metod can be invoked after
getEditorControls(parent) only
+JBOSSWS_BUTTON_FIELD_EDITOR_BROWSE=Browse...
+JBOSSWS_BUTTON_FIELD_EDITOR_NOT_IMPLEMENTED_YET=Not implemented yet. Please setup real
acion for editor.
+JBOSSWS_SWT_FIELD_EDITOR_FACTORY_BROWSE=Browse...
+JBOSSWS_SWT_FIELD_EDITOR_FACTORY_SELECT_HOME_FOLDER=Select JBossWS Home Folder
+JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NAME2=Name:
+JBOSSWS_PREFERENCE_PAGE_RUNTIMES=JBossWS Runtimes
\ No newline at end of file
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUIMessages.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUIMessages.java 2008-06-04
21:01:55 UTC (rev 8555)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUIMessages.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -68,6 +68,35 @@
public static String BIN;
public static String COMMOND;
+ public static String JBOSSWS_BASIC_EDITOR_COMPOSITE;
+ public static String JBOSSWS_BASIC_EDITOR_SUPPORT;
+ public static String JBOSSWS_BASE_EDITOR_DIFFERENT;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NAME;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_PATH;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_INPUTELEMENT_MUST_BE;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_AN_INSTANCEOF_OF_LIST;
+ public static String JBOSSWS_RUNTIME_DELETE_CONFIRM_TITLE;
+ public static String JBOSSWS_RUNTIME_DELETE_USED_CONFIRM;
+ public static String JBOSSWS_RUNTIME_DELETE_NOT_USED_CONFIRM;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_EDIT_RUNTIME;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_MODIFY_RUNTIME;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NEW_RUNTIME;
+ public static String
JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_PATH_TO_HOME_DIRECTORY_CANNOT_BE_EMPTY;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_ALREADY_EXISTS;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_RUNTIME;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_RUNTIME_NAME_IS_NOT_CORRECT;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NAME_CANNOT_BE_EMPTY;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_CREATE_A_RUNTIME;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_HOME_FOLDER;
+ public static String JBOSSWS_COMPOSITE_EDITOR_THIS_METOD_CAN_BE_INVOKED;
+ public static String JBOSSWS_BUTTON_FIELD_EDITOR_BROWSE;
+ public static String JBOSSWS_BUTTON_FIELD_EDITOR_NOT_IMPLEMENTED_YET;
+ public static String JBOSSWS_SWT_FIELD_EDITOR_FACTORY_BROWSE;
+ public static String JBOSSWS_SWT_FIELD_EDITOR_FACTORY_SELECT_HOME_FOLDER;
+ public static String JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NAME2;
+ public static String JBOSSWS_PREFERENCE_PAGE_RUNTIMES;
+
+
static {
NLS.initializeMessages(BUNDLE_NAME, JbossWSUIMessages.class);
}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/BaseField.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/BaseField.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/BaseField.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+import org.eclipse.swt.widgets.Control;
+
+public abstract class BaseField {
+
+ public static final String PROPERTY_NAME = "value"; //$NON-NLS-1$
+
+ private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public void firePropertyChange(Object oldValue, Object newValue) {
+ pcs.firePropertyChange(PROPERTY_NAME, oldValue, newValue);
+ }
+
+ abstract public Control getControl();
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/BaseFieldEditor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/BaseFieldEditor.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/BaseFieldEditor.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,328 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+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.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Widget;
+import org.jboss.tools.ws.ui.messages.JbossWSUIMessages;
+
+/**
+ * @author Grid Qian
+ */
+public abstract class BaseFieldEditor implements IFieldEditor {
+
+ PropertyChangeSupport pcs = new PropertyChangeSupport(this);
+
+ Set<DisposeListener> disposeListeners = new HashSet<DisposeListener>();
+
+ private Object value = new Object();
+
+ private String labelText;
+
+ private String nameText = null;
+
+ Label labelControl = null;
+
+ protected Map<Object, Object> data = null;
+
+ private boolean enabled = true;
+
+ /**
+ *
+ * @param name
+ * @param label
+ * @param defaultValue
+ */
+ public BaseFieldEditor(String name, String label,Object defaultValue) {
+ this.value = defaultValue;
+ this.labelText = label;
+ this.nameText = name;
+ }
+
+ /**
+ *
+ * @param parent
+ */
+ public void doFillIntoGrid(Object parent) {
+ Assert.isTrue(parent instanceof Composite,
JbossWSUIMessages.JBOSSWS_BASIC_EDITOR_COMPOSITE);
+ Assert.isTrue(((Composite)parent).getLayout() instanceof
GridLayout,JbossWSUIMessages.JBOSSWS_BASIC_EDITOR_SUPPORT);
+ Composite aComposite = (Composite) parent;
+ final Control[] controls = (Control[])getEditorControls(aComposite);
+ GridLayout gl = (GridLayout)((Composite)parent).getLayout();
+
+ doFillIntoGrid(aComposite,gl.numColumns);
+ if(controls.length>0) {
+ controls[0].addDisposeListener(new DisposeListener(){
+ public void widgetDisposed(DisposeEvent e) {
+ dispose();
+ controls[0].removeDisposeListener(this);
+ }
+ });
+ }
+ }
+
+ /**
+ * @param composite
+ * @param numColumns
+ */
+ protected void doFillIntoGrid(Composite composite, int numColumns) {
+
+ }
+
+ /**
+ *
+ */
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ /**
+ *
+ */
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ /**
+ *
+ * @param parent
+ * @return
+ */
+ public Label createLabelControl(Composite parent) {
+ if(labelControl==null) {
+ labelControl = new Label(parent,SWT.NO_BACKGROUND);
+ labelControl.setText(this.labelText);
+ } else if(parent!=null) {
+ if(labelControl.getParent()!=parent)
+ throw new IllegalArgumentException(JbossWSUIMessages.JBOSSWS_BASE_EDITOR_DIFFERENT);
+ }
+ return labelControl;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public Label getLabelControl() {
+ return createLabelControl(null);
+ }
+
+ /**
+ *
+ */
+ public abstract Object[] getEditorControls(Object composite);
+
+ /**
+ *
+ */
+ public abstract Object[] getEditorControls();
+
+ /**
+ *
+ * @return
+ */
+ public Control[] getSwtControls() {
+ return (Control[])getEditorControls();
+ }
+
+ /**
+ *
+ */
+ public abstract int getNumberOfControls();
+
+ /**
+ *
+ */
+ public Object getValue() {
+ return value;
+ }
+
+ /**
+ *
+ */
+ public String getValueAsString() {
+ return getValue().toString();
+ }
+
+ /**
+ *
+ */
+ public boolean isEnabled() {
+ return this.enabled ;
+ }
+
+ /**
+ *
+ */
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ Control[] controls = getSwtControls();
+ if(controls==null) {
+ return;
+ }
+ for(int i=0;i<controls.length;i++) {
+ Control control = controls[i];
+ control.setEnabled(enabled);
+ if(control instanceof Composite) {
+ setEnabled((Composite)control, enabled);
+ }
+ }
+ }
+
+ private void setEnabled(Composite composite, boolean enabled) {
+ Control[] controls = composite.getChildren();
+ for(int i=0;i<controls.length;i++) {
+ Control control = controls[i];
+ control.setEnabled(enabled);
+ if(control instanceof Composite) {
+ setEnabled((Composite)control, enabled);
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public boolean setFocus() {
+ return true;
+ }
+
+ /**
+ *
+ * @param newValue
+ */
+ public void setValue(Object newValue) {
+ Object oldValue = value;
+ value = newValue;
+ pcs.firePropertyChange(nameText,oldValue,newValue);
+ }
+
+ /**
+ *
+ */
+ public void setValueAsString(String stringValue) {
+ value = stringValue;
+ }
+
+ /**
+ *
+ */
+ public String getName() {
+ return nameText;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.ui.widget.editor.IFieldEditor#dispose()
+ */
+ public void dispose() {
+ PropertyChangeListener[] listeners = pcs.getPropertyChangeListeners();
+ for (int i = 0; i < listeners.length; i++) {
+ PropertyChangeListener propertyChangeListener = listeners[i];
+ pcs.removePropertyChangeListener(propertyChangeListener);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.seam.ui.widget.editor.IFieldEditor#dispose(org.eclipse.swt.events.DisposeEvent)
+ */
+ public void dispose(DisposeEvent e) {
+ dispose();
+ for (DisposeListener disposeListener : disposeListeners) {
+ disposeListener.widgetDisposed(e);
+ }
+ disposeListeners.clear();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.seam.ui.widget.editor.IFieldEditor#addDisposeListener(org.eclipse.swt.events.DisposeListener)
+ */
+ public void addDisposeListener(DisposeListener listener) {
+ disposeListeners.add(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.seam.ui.widget.editor.IFieldEditor#removeDisposeListener(org.eclipse.swt.events.DisposeListener)
+ */
+ public void removeDisposeListener(DisposeListener listener) {
+ disposeListeners.remove(listener);
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getLabelText() {
+ return labelText;
+ }
+
+ /**
+ *
+ * @param labelText
+ */
+ public void setLabelText(String labelText) {
+ this.labelText = labelText;
+ }
+
+ /**
+ *
+ */
+ private boolean editable = true;
+
+ /**
+ *
+ */
+ public boolean isEditable() {
+ return editable;
+ }
+
+ /**
+ *
+ */
+ public void setEditable(boolean aEditable) {
+ this.editable = aEditable;
+ }
+
+ public Object getData(Object key) {
+ if(data==null) {
+ return null;
+ }
+ return data.get(key);
+ }
+
+ public void setData(Object key, Object value) {
+ if(data==null) {
+ data = new HashMap<Object, Object>();
+ }
+ data.put(key, value);
+ }
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/ButtonFieldEditor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/ButtonFieldEditor.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/ButtonFieldEditor.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.jboss.tools.ws.ui.messages.JbossWSUIMessages;
+
+/**
+ * @author eskimo
+ *
+ */
+public class ButtonFieldEditor extends BaseFieldEditor {
+
+ PushButtonField button= null;
+
+ private ButtonPressedAction buttonAction = new
ButtonPressedAction(JbossWSUIMessages.JBOSSWS_BUTTON_FIELD_EDITOR_BROWSE) {
+ @Override
+ public void run() {
+ throw new
RuntimeException(JbossWSUIMessages.JBOSSWS_BUTTON_FIELD_EDITOR_NOT_IMPLEMENTED_YET);
+ }
+ };
+
+ public ButtonFieldEditor(String name, String label) {
+ super(name, label, new Object());
+ }
+
+ public ButtonFieldEditor(String name, ButtonPressedAction action, Object defaultValue)
{
+ super(name, action.getText(), defaultValue);
+ buttonAction = action;
+ buttonAction.setFieldEditor(this);
+ }
+
+ @Override
+ public void doFillIntoGrid(Object parent) {
+ }
+
+ @Override
+ public Object[] getEditorControls() {
+ if(button==null) {
+ return null;
+ }
+ return new Control[]{button.getControl()};
+ }
+
+ @Override
+ public boolean isEditable() {
+ return false;
+ }
+
+ public void save(Object object) {
+ }
+
+ @Override
+ public void setEditable(boolean ediatble) {
+ }
+
+ @Override
+ public Object[] getEditorControls(Object composite) {
+ if(button==null && composite!=null) {
+ button = new PushButtonField((Composite)composite,buttonAction);
+ setEnabled(isEnabled());
+ }
+ return new Control[]{button.getControl()};
+ }
+
+ public ButtonPressedAction getButtonaction() {
+ return buttonAction;
+ }
+
+ public static class ButtonPressedAction extends Action implements SelectionListener{
+
+ private IFieldEditor editor = null;
+
+ public ButtonPressedAction(String label) {
+ super(label);
+ }
+
+ public void setFieldEditor(IFieldEditor newEditor) {
+ editor = newEditor;
+ }
+
+ public IFieldEditor getFieldEditor() {
+ return editor;
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ run();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.ui.widget.editor.BaseFieldEditor#getNumberOfControls()
+ */
+ @Override
+ public int getNumberOfControls() {
+ return 1;
+ }
+}
\ No newline at end of file
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/CompositeEditor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/CompositeEditor.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/CompositeEditor.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+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.ws.ui.messages.JbossWSUIMessages;
+
+/**
+ * @author eskimo
+ *
+ */
+public class CompositeEditor extends BaseFieldEditor implements PropertyChangeListener {
+
+ public CompositeEditor(String name, String label, Object defaultValue) {
+ super(name, label, defaultValue);
+ }
+
+ @Override
+ public void doFillIntoGrid(Object parent) {
+ Assert.isTrue(parent instanceof Composite,
+ JbossWSUIMessages.JBOSSWS_BASIC_EDITOR_COMPOSITE);
+ Assert.isTrue(((Composite) parent).getLayout() instanceof GridLayout,
+ JbossWSUIMessages.JBOSSWS_BASIC_EDITOR_SUPPORT);
+
+ Composite aComposite = (Composite) parent;
+ final 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;
+ 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);
+ controls[i].setEnabled(isEnabled());
+
+ if(i==0) {
+ controls[i].addDisposeListener(new DisposeListener(){
+ public void widgetDisposed(DisposeEvent e) {
+ dispose();
+ controls[0].removeDisposeListener(this);
+ }
+ });
+ }
+ }
+ }
+
+ List<Control> controls = new ArrayList<Control>();
+
+ @Override
+ public Object[] getEditorControls() {
+ if(controls.size()>0) return controls.toArray();
+ else throw new
IllegalStateException(JbossWSUIMessages.JBOSSWS_COMPOSITE_EDITOR_THIS_METOD_CAN_BE_INVOKED);
+ }
+
+ @Override
+ public Object[] getEditorControls(Object parent) {
+ for (IFieldEditor editor : editors) {
+ controls.addAll(Arrays.asList((Control[])editor.getEditorControls(parent)));
+ }
+ return controls.toArray(new Control[]{});
+ }
+
+ @Override
+ public int getNumberOfControls() {
+ return editors.size();
+ }
+
+ @Override
+ public boolean isEditable() {
+ return true;
+ }
+
+ public void save(Object object) {
+ }
+
+ @Override
+ public void setEditable(boolean ediatble) {
+ }
+
+ List<IFieldEditor> editors = new ArrayList<IFieldEditor>();
+
+ public CompositeEditor addFieldEditors(IFieldEditor[] editors) {
+ this.editors.addAll( Arrays.asList(editors));
+ for (IFieldEditor editor : Arrays.asList(editors)) {
+ editor.addPropertyChangeListener(this);
+ }
+ return this;
+ }
+
+ @Override
+ public void setValue(Object newValue) {
+ for (IFieldEditor editor : editors) {
+ editor.removePropertyChangeListener(this);
+ editor.setValue(newValue);
+ editor.addPropertyChangeListener(this);
+ }
+ super.setValue(newValue);
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ for (IFieldEditor editor : editors) {
+ if(event.getSource()!=editor) {
+ editor.removePropertyChangeListener(this);
+ editor.setValue(event.getNewValue());
+ editor.addPropertyChangeListener(this);
+ }
+ }
+ super.setValue(event.getNewValue());
+ }
+
+ @Override
+ public void setEnabled(boolean set) {
+ for (IFieldEditor editor : editors) {
+ editor.setEnabled(set);
+ }
+ }
+
+ public List<IFieldEditor> getEditors() {
+ return Collections.unmodifiableList(editors);
+ }
+
+ public IFieldEditor getEditorByName(String name) {
+ for (IFieldEditor editor : editors) {
+ if(name.equals(editor.getName())) {
+ return editor;
+ }
+ }
+ return null;
+ }
+
+ public void setData(Object key, Object value) {
+ super.setData(key, value);
+ for (IFieldEditor editor : editors) {
+ editor.setData(key, value);
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/IFieldEditor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/IFieldEditor.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/IFieldEditor.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import java.beans.PropertyChangeListener;
+
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+
+/**
+ * @author Grid Qian
+ */
+public interface IFieldEditor extends INamedElement {
+
+ /**
+ *
+ * @param composite
+ */
+ public Object[] getEditorControls(Object composite);
+
+ /**
+ *
+ * @return
+ */
+ public Object[] getEditorControls();
+
+ /**
+ *
+ * @return
+ */
+ public int getNumberOfControls();
+
+ /**
+ *
+ * @param parent
+ */
+ public void doFillIntoGrid(Object parent);
+
+ /**
+ *
+ * @param listener
+ */
+ public void addPropertyChangeListener(PropertyChangeListener listener);
+
+ /**
+ *
+ * @param listener
+ */
+ public void addDisposeListener(DisposeListener listener);
+
+ /**
+ *
+ * @param listener
+ */
+ public void removeDisposeListener(DisposeListener listener);
+
+ /**
+ *
+ * @param listener
+ */
+ public void removePropertyChangeListener(PropertyChangeListener listener);
+
+ /**
+ *
+ * @return
+ */
+ public boolean isEditable();
+
+ /**
+ *
+ * @param aEdiatble
+ */
+ public void setEditable(boolean aEdiatble);
+
+ /**
+ * @return
+ *
+ */
+ public boolean setFocus();
+
+ /**
+ *
+ * @return
+ */
+ public boolean isEnabled();
+
+ /**
+ *
+ * @param enabled
+ */
+ public void setEnabled(boolean enabled);
+
+ /**
+ *
+ */
+ public void dispose();
+
+ /**
+ *
+ * @param e
+ */
+ public void dispose(DisposeEvent e);
+
+ /**
+ * Sets the application defined property of this editor
+ *
+ * @param data
+ * @param key
+ */
+ public void setData(Object key, Object data);
+
+ /**
+ * Gets the application defined property of this editor
+ *
+ * @param key
+ * @return
+ */
+ public Object getData(Object key);
+
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/INamedElement.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/INamedElement.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/INamedElement.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+/**
+ * @author Grid Qian
+ */
+public interface INamedElement {
+
+ public abstract String getName();
+
+ /**
+ *
+ * @return
+ */
+ public abstract Object getValue();
+
+ /**
+ *
+ */
+ public abstract void setValue(Object newValue);
+
+ /**
+ *
+ * @return
+ */
+ public abstract String getValueAsString();
+
+ /**
+ *
+ * @param aValue
+ */
+ public abstract void setValueAsString(String aValue);
+
+}
\ No newline at end of file
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,999 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+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;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+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.osgi.util.NLS;
+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.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.TableColumn;
+import org.jboss.tools.ws.ui.messages.JbossWSUIMessages;
+
+/**
+ * @author Grid Qian
+ */
+public class JbossRuntimeListFieldEditor 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 ActionPanel actionPanel;
+
+ private Map<JbossWSRuntime, JbossWSRuntime> changed = new
HashMap<JbossWSRuntime, JbossWSRuntime>();
+
+ private List<JbossWSRuntime> checkedElements = new
ArrayList<JbossWSRuntime>();
+
+ private List<JbossWSRuntime> added = new ArrayList<JbossWSRuntime>();
+
+ private List<JbossWSRuntime> removed = new ArrayList<JbossWSRuntime>();
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Control for editing jbossWSRuntime list
+ *
+ * @param name
+ * String
+ * @param label
+ * String
+ * @param defaultValue
+ * Object
+ */
+ public JbossRuntimeListFieldEditor(String name, String label,
+ Object defaultValue) {
+ super(name, label, defaultValue);
+ }
+
+ /**
+ * TBD
+ *
+ * @return List<JbossWSRuntime>
+ */
+ public List<JbossWSRuntime> getDefaultJbossWSRuntimes() {
+ return checkedElements;
+ }
+
+ /**
+ * TBD
+ *
+ * @return List<JbossWSRuntime>
+ */
+ public List<JbossWSRuntime> getAddedJbossWSRuntimes() {
+ return added;
+ }
+
+ /**
+ * TBD
+ *
+ * @return List<JbossWSRuntime>
+ */
+ public Map<JbossWSRuntime, JbossWSRuntime> getChangedJbossWSRuntimes() {
+ return changed;
+ }
+
+ /**
+ * TBD
+ *
+ * @return List<JbossWSRuntime>
+ */
+ public List<JbossWSRuntime> 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);
+ GridData gd = new GridData();
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ root.setLayoutData(gd);
+
+ root.setLayout(new FormLayout());
+ createTableView();
+ createActionBar();
+
+ FormData tableData = new FormData();
+ tableData.left = new FormAttachment(0,5);
+ tableData.right = new FormAttachment(actionPanel, -5);
+ tableData.top = new FormAttachment(0,5);
+ tableData.bottom = new FormAttachment(100,-5);
+ tableView.getControl().setLayoutData(tableData);
+
+ FormData actionsData = new FormData();
+ actionsData.top = new FormAttachment(0,5);
+ actionsData.bottom = new FormAttachment(100,-5);
+ actionsData.right = new FormAttachment(100,-5);
+ actionPanel.setLayoutData(actionsData);
+ return new Control[] {root};
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void createTableView() {
+ tableView = CheckboxTableViewer.newCheckList(root, SWT.V_SCROLL
+ | SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
+
+ 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(TC_NAME_WIDTH);
+ tc2.setText(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NAME);
+
+ TableColumn tc3 = new TableColumn(tableView.getTable(), SWT.LEFT);
+ tc3.setWidth(TC_PATH_WIDTH);
+ tc3.setText(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_PATH);
+
+ tableView.setContentProvider(new IStructuredContentProvider() {
+
+ @SuppressWarnings("unchecked")
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof List) {
+ return ((List<JbossWSRuntime>) inputElement).toArray();
+ } else {
+ throw new IllegalArgumentException(
+ JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_INPUTELEMENT_MUST_BE
+ + JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_AN_INSTANCEOF_OF_LIST);
+ }
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ viewer.refresh();
+ }
+ });
+
+ tableView.setLabelProvider(new ITableLabelProvider() {
+
+ private static final int TC_DEFAULT_NUMBER = 0;
+ private static final int TC_NAME_NUMBER = 1;
+ private static final int TC_PATH_NUMBER = 2;
+
+ 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) {
+ JbossWSRuntime rt = (JbossWSRuntime) element;
+ if (columnIndex == TC_DEFAULT_NUMBER) {
+ return ""; //$NON-NLS-1$
+ }
+ if (columnIndex == TC_NAME_NUMBER) {
+ return rt.getName();
+ }
+ 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() {
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ JbossWSRuntime selRt = (JbossWSRuntime) event.getElement();
+ if (event.getChecked()) {
+ JbossWSRuntime deselRt = null;
+ Object[] selRts = tableView.getCheckedElements();
+
+ for (int i = 0; i < selRts.length; i++) {
+ JbossWSRuntime rt = (JbossWSRuntime) selRts[i];
+ if (rt != selRt) {
+ deselRt = rt;
+ break;
+ }
+ }
+
+ if (deselRt != null) {
+ Object[] newChecked = new Object[selRts.length - 1];
+ checkedElements.clear();
+ int i = 0;
+ for (Object object : selRts) {
+ JbossWSRuntime rt = (JbossWSRuntime) object;
+ if (rt == selRt) {
+ newChecked[i] = rt;
+ checkedElements.add(rt);
+ i++;
+ }
+ }
+ tableView.setCheckedElements(newChecked);
+ } else {
+ checkedElements.add((JbossWSRuntime)event.getElement());
+ }
+ } else {
+ checkedElements.remove(selRt);
+ }
+ pcs.firePropertyChange(getName(), null, getValue());
+ }
+ });
+
+ for (JbossWSRuntime rt : (List<JbossWSRuntime>) getValue()) {
+ if (rt.isDefault()) {
+ tableView.setChecked(rt, true);
+ checkedElements.add(rt);
+ }
+ }
+ }
+
+ protected void createActionBar() {
+ actionPanel = new ActionPanel(root, new BaseAction[] {
+ new AddAction(), new EditAction(), new RemoveAction()});
+ tableView.addSelectionChangedListener(actionPanel);
+ }
+
+ /**
+ * Checks all runtimes and set default one if user did not do it.
+ */
+ @SuppressWarnings("unchecked")
+ private void setDefaultRuntimes() {
+ List<JbossWSRuntime> runtimes = (List<JbossWSRuntime>)getValue();
+ for (JbossWSRuntime jbossWSRuntime : runtimes) {
+ boolean checked = false;
+ for(JbossWSRuntime checkedElement: checkedElements) {
+ if(checkedElement == jbossWSRuntime) {
+ checked = true;
+ break;
+ }
+ }
+ if(!checked) {
+ tableView.setChecked(jbossWSRuntime, true);
+ checkedElements.add(jbossWSRuntime);
+ }
+ }
+ }
+
+ /**
+ * Return array of Controls that forms and editor
+ *
+ * @return Control[]
+ */
+ @Override
+ public Object[] getEditorControls() {
+ 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,
+ JbossWSUIMessages.JBOSSWS_BASIC_EDITOR_COMPOSITE);
+ Assert
+ .isTrue(
+ ((Composite) parent).getLayout() instanceof GridLayout,
+ JbossWSUIMessages.JBOSSWS_BASIC_EDITOR_SUPPORT);
+ Composite aComposite = (Composite) parent;
+ 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);
+ }
+
+ /**
+ * Wizard page for editing JbossWS Runtime parameters
+ *
+ */
+ public static class JbossWSRuntimeWizardPage extends WizardPage implements
+ PropertyChangeListener {
+
+ private static final String SRT_NAME = "name";
+ private static final String SRT_HOMEDIR = "homeDir";
+
+ private static final int GL_PARENT_COLUMNS = 1;
+ private static final int GL_CONTENT_COLUMNS = 3;
+
+ List<JbossWSRuntime> value = null;
+
+ IFieldEditor name = createTextEditor(
+ SRT_NAME, JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NAME2,
+ ""); //$NON-NLS-1$
+
+ IFieldEditor homeDir = createBrowseFolderEditor(
+ SRT_HOMEDIR,
+ JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_HOME_FOLDER,
+ ""); //$NON-NLS-1$
+
+ JbossWSRuntime current = null;
+
+ public JbossWSRuntimeWizardPage(List<JbossWSRuntime> editedList) {
+ super(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NEW_RUNTIME);
+
+ setMessage(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_CREATE_A_RUNTIME);
+ setTitle(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_RUNTIME);
+ value = editedList;
+ }
+
+ /**
+ * Create Wizard page content
+ *
+ * @param parent
+ * Composite - parent composite
+ */
+ public void createControl(Composite parent) {
+ 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(GL_CONTENT_COLUMNS, false);
+ root.setLayout(gl);
+ homeDir.doFillIntoGrid(root);
+ homeDir.addPropertyChangeListener(this);
+ name.doFillIntoGrid(root);
+ name.addPropertyChangeListener(this);
+ setPageComplete(false);
+ setControl(root);
+ }
+
+ /**
+ * Process evt: setup default values based on JbossWS Home folder and
+ * validate user input
+ *
+ * @param evt
+ * PropertyChangeEvent describes changes in wizard
+ */
+ public void propertyChange(java.beans.PropertyChangeEvent evt) {
+ if ("homeDir".equals(evt.getPropertyName())) {
+ if (name.getValueAsString() == null
+ || "".equals(name.getValueAsString().trim())) {
+ String homeDirName = homeDir.getValueAsString();
+ if (homeDirName != null && !"".equals(homeDirName.trim())) {
+ File folder = new File(homeDirName);
+ homeDirName = folder.getName();
+ }
+ name.setValue(homeDirName);
+ }
+ }
+
+ if (name.getValueAsString() == null || "".equals(//$NON-NLS-1$
+ name.getValueAsString().toString().trim())) {
+ setErrorMessage(JbossWSUIMessages.JBOSSWS_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(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_RUNTIME_NAME_IS_NOT_CORRECT);
+ setPageComplete(false);
+ return;
+ }
+ for (JbossWSRuntime rt : value) {
+ if (current != null && current.getName().equals(rt.getName())) {
+ continue;
+ }
+ if (rt.getName().equals(name.getValueAsString())) {
+ setErrorMessage(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_RUNTIME
+ + name.getValueAsString()
+ + JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_ALREADY_EXISTS);
+ setPageComplete(false);
+ return;
+ }
+ }
+
+ if (current != null
+ && current.getName().equals(name.getValueAsString())
+ && current.getHomeDir().equals(homeDir.getValueAsString())) {
+ setErrorMessage(null);
+ setPageComplete(false);
+ return;
+ }
+
+ if (homeDir.getValueAsString() == null
+ || "".equals(homeDir.getValueAsString().trim())) { //$NON-NLS-1$
+ setErrorMessage(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_PATH_TO_HOME_DIRECTORY_CANNOT_BE_EMPTY);
+ setPageComplete(false);
+ return;
+ }
+
+ setErrorMessage(null);
+ setPageComplete(true);
+ }
+
+ /**
+ * Return JbossWS Runtime instance initialized by user input
+ *
+ * @return JbossWSRuntime instance
+ */
+ public JbossWSRuntime getRuntime() {
+ JbossWSRuntime newRt = new JbossWSRuntime();
+ newRt.setName(name.getValueAsString());
+ newRt.setHomeDir(homeDir.getValueAsString());
+ return newRt;
+ }
+
+ public IFieldEditor createTextEditor(String name, String label, String defaultValue) {
+ CompositeEditor editor = new CompositeEditor(name,label, defaultValue);
+ editor.addFieldEditors(new IFieldEditor[]{new LabelFieldEditor(name,label),
+ new TextFieldEditor(name,label, defaultValue)});
+ return editor;
+ }
+
+ public IFieldEditor createBrowseFolderEditor(String name, String label, String
defaultValue) {
+ CompositeEditor editor = new CompositeEditor(name, label, defaultValue);
+ editor.addFieldEditors(new IFieldEditor[]{new LabelFieldEditor(name,label),
+ new TextFieldEditor(name,label, defaultValue),
+ new
ButtonFieldEditor(name,createSelectFolderAction(JbossWSUIMessages.JBOSSWS_SWT_FIELD_EDITOR_FACTORY_BROWSE),defaultValue)});
+ return editor;
+ }
+
+ public ButtonFieldEditor.ButtonPressedAction createSelectFolderAction(String
buttonName) {
+ return new ButtonFieldEditor.ButtonPressedAction(buttonName) {
+ @Override
+ public void run() {
+ DirectoryDialog dialog = new
DirectoryDialog(Display.getCurrent().getActiveShell());
+ dialog.setFilterPath(getFieldEditor().getValueAsString());
+ dialog.setMessage(JbossWSUIMessages.JBOSSWS_SWT_FIELD_EDITOR_FACTORY_SELECT_HOME_FOLDER);
+ dialog.setFilterPath(getFieldEditor().getValueAsString());
+ String directory = dialog.open();
+ if(directory!=null) {
+ getFieldEditor().setValue(directory);
+ }
+ }
+ };
+ }
+ }
+
+ /**
+ * Wizard collect information and creates new JbossWSRuntime instances.
+ *
+ */
+ public static class JbossWSRuntimeNewWizard extends Wizard {
+
+ JbossWSRuntimeWizardPage page1 = null;
+ List<JbossWSRuntime> added = null;
+ List<JbossWSRuntime> value = null;
+
+ public JbossWSRuntimeNewWizard(List<JbossWSRuntime>
exist,List<JbossWSRuntime> added) {
+ super();
+ setWindowTitle(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_NEW_RUNTIME);
+ page1 = new JbossWSRuntimeWizardPage(exist);
+ addPage(page1);
+ this.value = exist;
+ this.added = added;
+ }
+
+ /**
+ * Do finish steps
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean performFinish() {
+ JbossWSRuntime rt = page1.getRuntime();
+ added.add(rt);
+ value.add(rt);
+ return true;
+ }
+ }
+
+ /**
+ * Wizard for editing JbossWS Runrtime parameters: name, version and path to
+ * home folder
+ *
+ */
+ public static class JbossWSRuntimeEditWizard extends Wizard {
+ JbossWSRuntimeWizardPage page1 = null;
+ List<JbossWSRuntime> added = null;
+ Map<JbossWSRuntime, JbossWSRuntime> changed = null;
+ List<JbossWSRuntime> value = null;
+ JbossWSRuntime source = null;
+
+ /**
+ * Constructor with almost all initialization parameters
+ *
+ * @param existing
+ * List<JbossWSRuntime> - edited list of JbossWS Runtimes
+ * @param source
+ * JbossWSRuntime - edited JbossWS Runtime
+ * @param added
+ * List<JbossWSRuntime> - TBD
+ * @param changed
+ * List<JbossWSRuntime> - TBD
+ */
+ public JbossWSRuntimeEditWizard(List<JbossWSRuntime> existing,
+ JbossWSRuntime source, List<JbossWSRuntime> added,
+ Map<JbossWSRuntime, JbossWSRuntime> changed) {
+ super();
+ setWindowTitle(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_EDIT_RUNTIME);
+ page1 = new JbossWSRuntimeWizardPage(existing);
+ page1
+ .setMessage(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_MODIFY_RUNTIME);
+ page1
+ .setTitle(JbossWSUIMessages.JBOSSWS_RUNTIME_LIST_FIELD_EDITOR_EDIT_RUNTIME);
+ addPage(page1);
+ this.value = existing;
+ this.added = added;
+ this.changed = changed;
+ this.source = source;
+ page1.name.setValue(source.getName());
+ page1.homeDir.setValue(source.getHomeDir());
+ page1.current = source;
+ }
+
+ /**
+ * Perform operations to finish editing JbossWS Runtime parameters
+ *
+ * @return boolean - always true
+ */
+ @Override
+ public boolean performFinish() {
+ JbossWSRuntime rt = page1.getRuntime();
+ if (rt.getName().equals(source.getName())
+ && rt.getHomeDir().equals(source.getHomeDir())) {
+ return true;
+ }
+ if (added.contains(source) || changed.containsKey(source)) {
+ source.setName(rt.getName());
+ source.setHomeDir(rt.getName());
+ } else {
+ changed.put(rt, source);
+ int i = value.indexOf(source);
+ if (i >= 0) {
+ value.set(i, rt);
+ } else {
+ value.remove(source);
+ value.add(rt);
+ }
+ }
+ return true;
+ }
+ }
+
+ /**
+ * Composite that holds list of BaseActions and presents them as column of
+ * buttons
+ *
+ */
+ 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));
+ 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());
+ }
+ }
+ }
+
+ /**
+ * Class represents an BaseAction as SWT button control and runs action when
+ * button is prtessed
+ *
+ */
+ public static class ActionButton implements IPropertyChangeListener {
+
+ 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;
+ 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) {
+ ActionButton.this.action.run();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ }
+
+ /**
+ * 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());
+ }
+ }
+ }
+
+ /**
+ * Action that changes state enable/disable based on current table selection
+ *
+ */
+ public abstract class BaseAction extends Action {
+
+ JbossWSRuntime[] runtimes = new JbossWSRuntime[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<JbossWSRuntime> rts = new ArrayList<JbossWSRuntime>();
+ for (Object rt : ((IStructuredSelection) selection).toArray()) {
+ rts.add((JbossWSRuntime) rt);
+ }
+ runtimes = rts.toArray(new JbossWSRuntime[] {});
+ } else {
+ runtimes = new JbossWSRuntime[0];
+ }
+ updateEnablement();
+ }
+
+ protected abstract void updateEnablement();
+ }
+
+ /**
+ * Action that invokes New JbossWS Runtime Dialog
+ *
+ */
+ public class AddAction extends BaseAction {
+
+ static final String ACTION_NAME = "&Add";
+
+ /**
+ * Constructor create Add action with default name
+ */
+ public AddAction() {
+ super(ACTION_NAME);
+ // This action is always available
+ setEnabled(true);
+ }
+
+ /**
+ * Do nothing, because Add action should be always available
+ */
+ @Override
+ protected void updateEnablement() {
+ // Add button is always available
+ }
+
+ /**
+ * Invoke New JbossWS Runtime Dialog
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void run() {
+ Wizard wiz = new JbossWSRuntimeNewWizard(
+ (List<JbossWSRuntime>) getValue(), added);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent()
+ .getActiveShell(), wiz);
+ dialog.open();
+ tableView.refresh();
+ setDefaultRuntimes();
+ }
+ }
+
+ /**
+ * Action starts an editing selected JbossWS Runtime in Edit JbossWS Runtime
+ * dialog
+ *
+ */
+ 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 JbossWS Runtime is selected
+ */
+ @Override
+ protected void updateEnablement() {
+ // available when the only JbossWSRuntime is selected
+ setEnabled(runtimes.length == 1);
+ }
+
+ /**
+ * Start editing selected JbossWS Runtime in Edit JbossWS Runtime Wizard
+ * Dialog
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void run() {
+ JbossWSRuntime selected = runtimes[0];
+ Wizard wiz = new JbossWSRuntimeEditWizard(
+ (List<JbossWSRuntime>) getValue(), runtimes[0], added, changed);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent()
+ .getActiveShell(), wiz);
+ dialog.open();
+ tableView.refresh();
+ if (changed.containsValue(selected)) {
+ JbossWSRuntime c = findChangedRuntime(selected);
+ if (c != null) {
+ tableView.setSelection(new StructuredSelection(c));
+ }
+ }
+ }
+
+ private JbossWSRuntime findChangedRuntime(JbossWSRuntime source) {
+ for (JbossWSRuntime r : changed.keySet()) {
+ if (source == changed.get(r)) {
+ return r;
+ }
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Action deletes all selected JbossWS Runtimes. A warning message is shown for
+ * used JbossWS Runtimes
+ *
+ */
+ public class RemoveAction extends BaseAction {
+
+ static final String ACTION_NAME = "&Remove";
+ /**
+ * Create DeleteAction action with default name
+ */
+ public RemoveAction() {
+ super(ACTION_NAME);
+ }
+
+ @Override
+ protected void updateEnablement() {
+ setEnabled(runtimes.length > 0);
+ }
+
+ /**
+ * Remove all selected JbossWS Runtimes one by one
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ for (JbossWSRuntime rt : runtimes) {
+ removeRuntime(rt);
+ }
+ tableView.refresh();
+ setDefaultRuntimes();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void removeRuntime(JbossWSRuntime r) {
+ boolean used = isRuntimeUsed(r.getName());
+ String title = JbossWSUIMessages.JBOSSWS_RUNTIME_DELETE_CONFIRM_TITLE;
+ String message = (used) ? NLS.bind(
+ JbossWSUIMessages.JBOSSWS_RUNTIME_DELETE_USED_CONFIRM, r.getName())
+ : NLS.bind(JbossWSUIMessages.JBOSSWS_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);
+ }
+ checkedElements.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;
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntime.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntime.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntime.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,128 @@
+package org.jboss.tools.ws.ui.preferences;
+
+public class JbossWSRuntime {
+
+ String name = null;
+
+ String homeDir = null;
+
+ boolean defaultRt = false;
+
+ /**
+ * Default constructor
+ */
+ public JbossWSRuntime() {
+ }
+
+ /**
+ * Get JbossWSRuntime name
+ *
+ * @return name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get path to home directory
+ *
+ * @return home directory path as string
+ */
+ public String getHomeDir() {
+ return homeDir;
+ }
+
+ /**
+ * Set JbossWSRuntime name
+ *
+ * @param name
+ * new JbossWSRuntime name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Set home directory
+ *
+ * @param homeDir
+ * new JbossWSRuntime's home directory
+ */
+ public void setHomeDir(String homeDir) {
+ this.homeDir = homeDir;
+ }
+
+ /**
+ * Mark runtime as default
+ *
+ * @param b
+ * new value for default property
+ */
+ public void setDefault(boolean b) {
+ this.defaultRt = b;
+ }
+
+ /**
+ * Get default flag
+ *
+ * @return default property
+ */
+ public boolean isDefault() {
+ return defaultRt;
+ }
+
+ /**
+ * Calculate path to seam-gen
+ *
+ * @return absolute path to seam-gen folder
+ */
+ public String getSeamGenDir() {
+ return getHomeDir() + "/seam-gen"; //$NON-NLS-1$
+ }
+
+ /**
+ * Calculate path to source templates
+ *
+ * @return absolute path to source templates
+ */
+ public String getSrcTemplatesDir() {
+ return getSeamGenDir() + "/src"; //$NON-NLS-1$
+ }
+
+ /**
+ * Calculate path to view templates
+ *
+ * @return absolute path to view templates
+ */
+ public String getViewTemplatesDir() {
+ return getSeamGenDir() + "/view"; //$NON-NLS-1$
+ }
+
+ /**
+ * Calculate path to resource templates
+ *
+ * @return absolute path to resource templates
+ */
+ public String getResourceTemplatesDir() {
+ return getSeamGenDir() + "/resources"; //$NON-NLS-1$
+ }
+
+ /**
+ * Calculate path to test templates
+ *
+ * @return absolute path to test templates
+ */
+ public String getTestTemplatesDir() {
+ return getSeamGenDir() + "/test"; //$NON-NLS-1$
+ }
+
+ /**
+ * Calculate path to templates root directory
+ *
+ * @return absolute path to templates root directory
+ */
+ public String getTemplatesDir() {
+ return getSeamGenDir();
+ }
+
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimeListConverter.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimeListConverter.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimeListConverter.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,87 @@
+package org.jboss.tools.ws.ui.preferences;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+public class JbossWSRuntimeListConverter {
+
+ /*
+ * Constants definitions
+ */
+ private static final String REGEXP_ESCAPE = "\\";
+ private static final String COMMA = ",";
+ private static final String EMPTY_STRING = "";
+ private static final String FIELD_SEPARATOR = "|";
+ private static final String DEFAULT = "default";
+ private static final String HOME_DIR = "homeDir";
+ private static final String NAME = "name";
+
+ /**
+ * Load String to SeamRuntime map from String
+ * @param input
+ * String representation of map
+ * @return
+ * Map<String, SeamRuntime> loaded from string
+ * TODO - switch to XML?
+ * TODO - write converter from old serialization format to XML?
+ * TODO - handle errors in string format
+ */
+ public Map<String, JbossWSRuntime> getMap(String input) {
+
+ Map<String, JbossWSRuntime> result = new HashMap<String,
JbossWSRuntime>();
+ if (input == null || EMPTY_STRING.equals(input.trim())) {
+ return result;
+ }
+ StringTokenizer runtimes = new StringTokenizer(input, COMMA);
+ while (runtimes.hasMoreTokens()) {
+ String runtime = runtimes.nextToken();
+ String[] map = runtime.split(REGEXP_ESCAPE + FIELD_SEPARATOR);
+ JbossWSRuntime rt = new JbossWSRuntime();
+ final int step = 2;
+ for (int i = 0; i < map.length; i += step) {
+ String name = map[i];
+ String value = i + 1 < map.length ? map[i + 1] : EMPTY_STRING;
+ if (NAME.equals(name)) {
+ rt.setName(value);
+ } else if (HOME_DIR.equals(name)) {
+ rt.setHomeDir(value);
+ } else if (DEFAULT.equals(name)) {
+ rt.setDefault(Boolean.parseBoolean(value));
+ }
+ }
+ result.put(rt.getName(), rt);
+ }
+
+ return result;
+ }
+
+ /**
+ * Convert map String to SeamRUntime to string representation
+ * @param runtimeMap
+ * Map<String, SeamRuntime> - map of String to Seam Runtime to convert
+ * in String
+ * @return
+ * String representation of String to Seam Runtime map
+ */
+ public String getString(Map<String, JbossWSRuntime> runtimeMap) {
+ StringBuffer buffer = new StringBuffer();
+ JbossWSRuntime[] runtimes = runtimeMap.values().toArray(
+ new JbossWSRuntime[runtimeMap.size()]);
+ for (int i = 0; i < runtimes.length; i++) {
+ buffer.append(NAME).append(FIELD_SEPARATOR);
+ buffer.append(runtimes[i].getName());
+ buffer.append(FIELD_SEPARATOR).append(HOME_DIR).append(
+ FIELD_SEPARATOR);
+ buffer.append(runtimes[i].getHomeDir());
+ buffer.append(FIELD_SEPARATOR).append(DEFAULT).append(
+ FIELD_SEPARATOR);
+ buffer.append(runtimes[i].isDefault());
+ if (i != runtimes.length - 1) {
+ buffer.append(COMMA);
+ }
+ }
+ return buffer.toString();
+ }
+ }
+
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimeManager.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimeManager.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimeManager.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,259 @@
+package org.jboss.tools.ws.ui.preferences;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.preference.IPersistentPreferenceStore;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.jboss.tools.ws.core.JbossWSCorePlugin;
+
+public class JbossWSRuntimeManager {
+
+ private static JbossWSRuntimeListConverter converter = new
JbossWSRuntimeListConverter();
+
+ private Map<String, JbossWSRuntime> runtimes = new HashMap<String,
JbossWSRuntime>();
+
+ /**
+ * Private constructor
+ */
+ private JbossWSRuntimeManager() {
+ IPreferenceStore ps = JbossWSCorePlugin.getDefault().getPreferenceStore();
+
+ String runtimeListString = ps.getDefaultString("jbosswsruntimelocation");
+
+ runtimes = converter.getMap(runtimeListString);
+ }
+
+ /**
+ * This class make Java Runtime responsible for solving synchronization
+ * problems during initialization if there is any
+ *
+ */
+ static class JbossWSRuntimeManagerHolder {
+ private static final JbossWSRuntimeManager INSTANCE = new JbossWSRuntimeManager();
+ }
+
+ /**
+ * Return SeamRuntimeManaher instance
+ *
+ * @return
+ * SeamRuntimeManager instance
+ */
+ public static JbossWSRuntimeManager getInstance() {
+ return JbossWSRuntimeManagerHolder.INSTANCE;
+ }
+
+ /**
+ * Return Array of configured SeamRuntimes
+ *
+ * @return
+ * SeamRuntime[]
+ */
+ public JbossWSRuntime[] getRuntimes() {
+ Collection<JbossWSRuntime> c = runtimes.values();
+ return c.toArray(new JbossWSRuntime[runtimes.size()]);
+ }
+
+ /**
+ * Add new SeamRuntime
+ *
+ * @param runtime
+ * SeamRuntime
+ */
+ public void addRuntime(JbossWSRuntime runtime) {
+ if (runtimes.size() == 0) {
+ runtime.setDefault(true);
+ }
+
+ JbossWSRuntime oldDefaultRuntime = getDefaultRuntime();
+ if (oldDefaultRuntime != null && runtime.isDefault()) {
+ oldDefaultRuntime.setDefault(false);
+ }
+ runtimes.put(runtime.getName(), runtime);
+ save();
+ }
+
+ /**
+ * Add new SeamRuntime with given parameters
+ *
+ * @param name
+ * String - runtime name
+ * @param path
+ * String - runtime home folder
+ * @param version
+ * String - string representation of version number
+ * @param defaultRt
+ * boolean - default flag
+ */
+ public void addRuntime(String name, String path,
+ boolean defaultRt) {
+ JbossWSRuntime seamRt = new JbossWSRuntime();
+ seamRt.setHomeDir(path);
+ seamRt.setName(name);
+ seamRt.setDefault(defaultRt);
+ addRuntime(seamRt);
+ }
+
+ /**
+ * Return SeamRuntime by given name
+ *
+ * @param name
+ * String - SeamRuntime name
+ * @return
+ * SeamRuntime - found SeamRuntime instance or null
+ */
+ public JbossWSRuntime findRuntimeByName(String name) {
+ for (JbossWSRuntime seamRuntime : runtimes.values()) {
+ if (seamRuntime.getName().equals(name)) {
+ return seamRuntime;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Remove given SeamRuntime from manager
+ * @param rt
+ * SeamRuntime
+ */
+ public void removeRuntime(JbossWSRuntime rt) {
+ runtimes.remove(rt.getName());
+ }
+
+
+ /**
+ * Save preference value and force save changes to disk
+ */
+ public void save() {
+ JbossWSCorePlugin.getDefault().getPreferenceStore().setValue(
+ "jbosswsruntimelocation",
+ converter.getString(runtimes));
+ IPreferenceStore store = JbossWSCorePlugin.getDefault().getPreferenceStore();
+ if (store instanceof IPersistentPreferenceStore) {
+ try {
+ ((IPersistentPreferenceStore) store).save();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Marks this runtime as default. Marks other runtimes with the same version as not
default.
+ * @param runtime
+ */
+ public void setDefaultRuntime(JbossWSRuntime runtime) {
+ JbossWSRuntime[] runtimes = getRuntimes();
+ for (int i = 0; i < runtimes.length; i++) {
+ runtimes[i].setDefault(false);
+ }
+ runtime.setDefault(true);
+ }
+
+ /**
+ * Return first default SeamRuntime
+ *
+ * @return
+ * SeamRuntime
+ */
+ public JbossWSRuntime getDefaultRuntime() {
+ for (JbossWSRuntime rt : runtimes.values()) {
+ if (rt.isDefault()) {
+ return rt;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * If project has seam facet then this method returns default seam runtime for proper
version of facet.
+ * Otherwise return first default runtime.
+ * @param project
+ * @return
+ */
+ public static JbossWSRuntime getDefaultRuntimeForProject(IProject project) {
+ if(project==null) {
+ throw new IllegalArgumentException("Project must not be null.");
+ }
+ try {
+ IProjectFacet facet =
ProjectFacetsManager.getProjectFacet("jbossws.core");
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project);
+ if(facetedProject!=null) {
+ return getInstance().getDefaultRuntime();
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ }
+ return getInstance().getDefaultRuntime();
+ }
+
+ /**
+ * Return list of available SeamRuntime names
+ *
+ * @return
+ * List<String>
+ */
+ public List<String> getRuntimeNames() {
+ JbossWSRuntime[] rts = getRuntimes();
+ List<String> result = new ArrayList<String>();
+ for (JbossWSRuntime seamRuntime : rts) {
+ result.add(seamRuntime.getName());
+ }
+ return result;
+ }
+
+ /**
+ * Return a list of all runtime names
+ *
+ * @return
+ * List of all runtime names
+ */
+ public List<String> getAllRuntimeNames() {
+ JbossWSRuntime[] rts = getRuntimes();
+ List<String> result = new ArrayList<String>();
+ for (JbossWSRuntime seamRuntime : rts) {
+ result.add(seamRuntime.getName());
+ }
+ return result;
+ }
+
+ /**
+ * TBD
+ *
+ * @param oldName
+ * old runtime name
+ * @param newName
+ * new runtime name
+ */
+ public void changeRuntimeName(String oldName, String newName) {
+ JbossWSRuntime o = findRuntimeByName(oldName);
+ if (o == null) {
+ return;
+ }
+ o.setName(newName);
+ onRuntimeNameChanged(oldName, newName);
+ }
+
+ private void onRuntimeNameChanged(String oldName, String newName) {
+ IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+// for (int i = 0; i < ps.length; i++) {
+// ISeamProject sp = SeamCorePlugin.getSeamProject(ps[i], false);
+// if (sp != null && oldName.equals(sp.getRuntimeName())) {
+// sp.setRuntimeName(newName);
+// }
+// }
+ }
+}
\ No newline at end of file
Copied:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage2.java
(from rev 8527,
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage.java)
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage2.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage2.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,201 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import java.io.File;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.jboss.tools.ws.core.JbossWSCorePlugin;
+import org.jboss.tools.ws.core.messages.JbossWSCoreMessages;
+import org.jboss.tools.ws.ui.JbossWSUIPlugin;
+import org.jboss.tools.ws.ui.messages.JbossWSUIMessages;
+import org.jboss.tools.ws.ui.utils.UIUtils;
+
+/**
+ * @author Grid Qian
+ */
+public class JbossWSRuntimePreferencePage2 extends PreferencePage implements
+ IWorkbenchPreferencePage {
+
+ private Text jbosswsPath;
+ private Label statusLabel;
+
+ protected Control createContents(Composite superparent) {
+
+ IPreferenceStore ps = JbossWSCorePlugin.getDefault()
+ .getPreferenceStore();
+ this.setPreferenceStore(ps);
+
+ UIUtils uiUtils = new UIUtils(JbossWSUIPlugin.PLUGIN_ID);
+ final Composite mainComp = uiUtils.createComposite(superparent, 1);
+
+ TabFolder jbosswsPreferenceTab = new TabFolder(mainComp, SWT.WRAP);
+ jbosswsPreferenceTab.setLayoutData(new GridData(
+ GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL
+ | GridData.FILL_BOTH));
+
+ TabItem runtimeInstalLocationItem = new TabItem(jbosswsPreferenceTab,
+ SWT.WRAP);
+ runtimeInstalLocationItem.setText(JbossWSUIMessages.JBOSSWS_RUNTIME);
+ runtimeInstalLocationItem
+ .setToolTipText(JbossWSUIMessages.JBOSSWS_RUNTIME_TOOLTIP);
+
+ Composite runtimeTab = uiUtils.createComposite(jbosswsPreferenceTab, 1);
+ runtimeTab.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
+ Composite runtimeGroup = uiUtils.createComposite(runtimeTab, 3);
+
+ runtimeInstalLocationItem.setControl(runtimeTab);
+ runtimeTab.setToolTipText(JbossWSUIMessages.JBOSSWS_RUNTIME_TOOLTIP);
+
+ jbosswsPath = uiUtils.createText(runtimeGroup,
+ JbossWSUIMessages.JBOSSWS_RUNTIME_LOCATION, null, null,
+ SWT.BORDER);
+
+ Button browseButton = uiUtils.createPushButton(runtimeGroup,
+ JbossWSUIMessages.LABEL_BROUSE, null, null);
+ browseButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handleBrowse(mainComp.getShell());
+ }
+ });
+
+ jbosswsPath.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ statusUpdate(runtimeExist(jbosswsPath.getText()));
+
+ }
+ });
+ new Label(runtimeTab, SWT.HORIZONTAL);
+ statusLabel = new Label(runtimeTab, SWT.BACKGROUND | SWT.READ_ONLY | SWT.CENTER |
SWT.WRAP | SWT.H_SCROLL);
+ statusLabel.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
+
+ initializeValues();
+ jbosswsPreferenceTab.setEnabled(true);
+ jbosswsPreferenceTab.setVisible(true);
+ return mainComp;
+ }
+
+ public void init(IWorkbench workbench) {
+ }
+
+ /**
+ * Pops up the file browse dialog box
+ */
+ private void handleBrowse(Shell parent) {
+ DirectoryDialog fileDialog = new DirectoryDialog(parent);
+ String fileName = fileDialog.open();
+ if (fileName != null) {
+ jbosswsPath.setText(fileName);
+ }
+ }
+
+ private void statusUpdate(boolean status) {
+ if (statusLabel != null) {
+ if (!jbosswsPath.getText().equals("")) {
+ if (status) {
+ statusLabel
+ .setText(JbossWSUIMessages.LABEL_JBOSSWS_RUNTIME_LOAD);
+ } else {
+ statusLabel
+ .setText(JbossWSUIMessages.LABEL_JBOSSWS_RUNTIME_LOAD_ERROR);
+ }
+ } else {
+ statusLabel
+ .setText(JbossWSUIMessages.LABEL_JBOSSWS_RUNTIME_NOT_EXIT);
+ }
+ }
+ }
+
+ private boolean runtimeExist(String path) {
+
+ File jbosswsHomeDir = new File(path);
+ if (!jbosswsHomeDir.isDirectory())
+ return false;
+ String[] newNode = {JbossWSUIMessages.BIN, JbossWSUIMessages.COMMOND};
+ String jbosswsBinPath = UIUtils.addNodesToPath(jbosswsHomeDir.getAbsolutePath(),
newNode);
+ if(new File(jbosswsBinPath).isFile()){
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * store the location to the preference
+ */
+ private void storeValues() {
+ IPreferenceStore store = this.getPreferenceStore();
+ store.setValue(JbossWSCoreMessages.WS_LOCATION, jbosswsPath.getText());
+ }
+
+ /**
+ * Initializes location using default values in the preference store.
+ */
+ private void initializeDefaults() {
+ IPreferenceStore preferenceStore = this.getPreferenceStore();
+ jbosswsPath.setText(preferenceStore
+ .getDefaultString("jbosswsruntimelocation"));
+ }
+
+ /**
+ * Initializes the location using default values in the preference
+ */
+ private void initializeValues() {
+ IPreferenceStore preferenceStore = this.getPreferenceStore();
+ jbosswsPath
+ .setText(preferenceStore.getString("jbosswsruntimelocation"));
+
+ }
+
+ /**
+ * Default button has been pressed.
+ */
+ protected void performDefaults() {
+ super.performDefaults();
+ initializeDefaults();
+ }
+
+ /**
+ * Apply button has been pressed.
+ */
+ protected void performApply() {
+ performOk();
+ }
+
+ /**
+ * OK button has been pressed.
+ */
+ public boolean performOk() {
+ storeValues();
+ return true;
+ }
+
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/LabelFieldEditor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/LabelFieldEditor.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/LabelFieldEditor.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * @author eskimo
+ *
+ */
+public class LabelFieldEditor extends BaseFieldEditor {
+
+ public LabelFieldEditor(String name, String label) {
+ super(name, label, ""); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.seam.ui.widget.editor.BaseFieldEditor#doFillIntoGrid(java.lang.Object)
+ */
+ @Override
+ public void doFillIntoGrid(Object parent) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.seam.ui.widget.editor.BaseFieldEditor#getEditorControls(java.lang.Object)
+ */
+ @Override
+ public Object[] getEditorControls(Object composite) {
+ // TODO Auto-generated method stub
+ return new Control[]{createLabelControl((Composite)composite)};
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.ui.widget.editor.BaseFieldEditor#getEditorControls()
+ */
+ @Override
+ public Object[] getEditorControls() {
+ return getEditorControls(null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.ui.widget.editor.IFieldEditor#isEditable()
+ */
+ @Override
+ public boolean isEditable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.ui.widget.editor.IFieldEditor#save(java.lang.Object)
+ */
+ public void save(Object object) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.ui.widget.editor.IFieldEditor#setEditable(boolean)
+ */
+ @Override
+ public void setEditable(boolean ediatble) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setValue(Object value) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.ui.widget.editor.BaseFieldEditor#getNumberOfControls()
+ */
+ @Override
+ public int getNumberOfControls() {
+ // TODO Auto-generated method stub
+ return 1;
+ }
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/PushButtonField.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/PushButtonField.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/PushButtonField.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,31 @@
+package org.jboss.tools.ws.ui.preferences;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.jboss.tools.ws.ui.preferences.ButtonFieldEditor.ButtonPressedAction;
+
+/**
+ * @author eskimo
+ *
+ */
+public class PushButtonField extends BaseField {
+
+ Button button;
+
+ /**
+ *
+ */
+ @Override
+ public Control getControl() {
+ return button;
+ }
+
+
+ public PushButtonField(Composite composite, ButtonPressedAction listener) {
+ button = new Button(composite,SWT.PUSH);
+ button.setText(listener.getText());
+ button.addSelectionListener(listener);
+ }
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/TextField.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/TextField.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/TextField.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+
+public class TextField extends BaseField implements ModifyListener{
+
+
+ Text textField = null;
+
+ public TextField(Composite parent, int style) {
+ textField = new Text(parent,style);
+ textField.addModifyListener(this);
+ }
+
+ public void modifyText(ModifyEvent e) {
+ firePropertyChange(new Object(),((Text)e.widget).getText().trim());
+ }
+
+ public Text getTextControl() {
+ return textField;
+ }
+
+ public Control getControl() {
+ return getTextControl();
+ }
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/TextFieldEditor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/TextFieldEditor.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/TextFieldEditor.java 2008-06-05
06:46:49 UTC (rev 8556)
@@ -0,0 +1,249 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ws.ui.preferences;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Collection;
+
+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.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.ws.ui.messages.JbossWSUIMessages;
+
+/**
+ *
+ * @author eskimo
+ *
+ */
+public class TextFieldEditor extends BaseFieldEditor implements PropertyChangeListener{
+
+ /**
+ *
+ */
+ public static final int UNLIMITED = -1;
+
+ protected int style = -1;
+
+ /**
+ *
+ * @param name
+ * @param aLabelText
+ * @param defaultvalue
+ */
+ public TextFieldEditor(String name,String aLabelText,String defaultvalue) {
+ super(name, aLabelText, defaultvalue);
+ }
+
+ /**
+ *
+ * @param name
+ * @param aLabelText
+ * @param defaultvalue
+ * @param editable
+ */
+ public TextFieldEditor(String name,String aLabelText,String defaultvalue,boolean
editable) {
+ super(name, aLabelText, defaultvalue);
+ setEditable(editable);
+ }
+
+ /**
+ *
+ */
+ protected TextField fTextField = null;
+
+ /**
+ *
+ */
+ protected int fWidthInChars = 0;
+
+ /**
+ *
+ */
+ @Override
+ public Object[] getEditorControls() {
+ return new Control[] {getTextControl()};
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.seam.ui.widget.editor.BaseFieldEditor#doFillIntoGrid(java.lang.Object)
+ */
+ @Override
+ public void doFillIntoGrid(Object aParent) {
+ Assert.isTrue(aParent instanceof Composite,
JbossWSUIMessages.JBOSSWS_BASIC_EDITOR_COMPOSITE);
+ Assert.isTrue(((Composite)aParent).getLayout() instanceof
GridLayout,JbossWSUIMessages.JBOSSWS_BASIC_EDITOR_SUPPORT);
+ Composite aComposite = (Composite) aParent;
+ getEditorControls(aComposite);
+ GridLayout gl = (GridLayout)((Composite)aParent).getLayout();
+ getTextControl(aComposite);
+
+ GridData gd = new GridData();
+
+ gd.horizontalSpan = gl.numColumns - 1;
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = true;
+
+ fTextField.getTextControl().setLayoutData(gd);
+ }
+
+ /**
+ *
+ * @param parent
+ * @return
+ */
+ public Text getTextControl(Composite parent) {
+ if (fTextField == null) {
+ fTextField = new TextField(parent, getInitialStyle());
+ Text textField = fTextField.getTextControl();
+ textField.setFont(parent.getFont());
+ textField.setText(getValue().toString());
+ textField.setEditable(isEditable());
+ textField.setEnabled(isEnabled());
+ fTextField.addPropertyChangeListener(this);
+ } else if (parent!=null){
+ Assert.isTrue(parent==fTextField.getTextControl().getParent());
+ }
+ return fTextField.getTextControl();
+ }
+
+ /**
+ *
+ */
+ protected void updateWidgetValues() {
+ setValueAsString(getValueAsString());
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected int getInitialStyle() {
+ if(this.style >= 0) return style;
+ return SWT.SINGLE | SWT.BORDER;
+ }
+
+ /*
+ * @param value
+ * @return
+ */
+ @SuppressWarnings({ "unchecked", "unused" })
+ private String checkCollection(Object value){
+
+ return value != null && (((Collection)value).size() > 0) ?
prepareCollectionToString((Collection)value) : ""; //$NON-NLS-1$
+ }
+
+ /*
+ * @param collection
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ private String prepareCollectionToString(Collection collection)
+ {
+ String stringValue = ""; //$NON-NLS-1$
+ Object[] objects = collection.toArray();
+ for(int i = 0; i < objects.length; i++){
+ stringValue += objects[i];
+ if(i < objects.length - 1)
+ stringValue += " "; //$NON-NLS-1$
+ }
+ return stringValue;
+ }
+
+
+ /*
+ * @param value
+ * @return
+ */
+ @SuppressWarnings("unused")
+ private String checkSimple(Object value){
+ return (value != null) ? value.toString() : ""; //$NON-NLS-1$
+ }
+
+ /**
+ *
+ */
+ @Override
+ public int getNumberOfControls() {
+ return 2;
+ }
+
+ /**
+ * Returns this field editor's text control.
+ *
+ * @return the text control, or <code>null</code> if no
+ * text field is created yet
+ */
+ protected Text getTextControl() {
+ return fTextField!=null?fTextField.getTextControl():null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.ui.widget.editor.BaseFieldEditor#setFocus()
+ */
+ @Override
+ public boolean setFocus() {
+ boolean setfocus = false;
+ if(fTextField!=null && !fTextField.getTextControl().isDisposed())
+ setfocus = fTextField.getTextControl().setFocus();
+ return setfocus;
+ }
+
+ /**
+ *
+ */
+ @Override
+ public Object[] getEditorControls(Object composite) {
+ return new Control[]{getTextControl((Composite)composite)};
+ }
+
+ /**
+ *
+ * @param object
+ */
+ public void save(Object object) {
+ }
+
+ /**
+ *
+ */
+ @Override
+ public void setValue(Object newValue) {
+ super.setValue(newValue);
+ if(fTextField!=null){
+ fTextField.removePropertyChangeListener(this);
+ fTextField.getTextControl().setText(newValue.toString());
+ fTextField.addPropertyChangeListener(this);
+ }
+ }
+
+ /**
+ *
+ */
+ @Override
+ public void setEditable(boolean aEditable) {
+ super.setEditable(aEditable);
+ if(getTextControl()!=null) getTextControl().setEditable(aEditable);
+ }
+
+ /**
+ *
+ */
+ public void propertyChange(PropertyChangeEvent evt) {
+ super.setValue(evt.getNewValue());
+ }
+}
\ No newline at end of file