Author: dennyxu
Date: 2008-06-12 03:19:23 -0400 (Thu, 12 Jun 2008)
New Revision: 8738
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/icons/
trunk/ws/plugins/org.jboss.tools.ws.ui/icons/obj16/
trunk/ws/plugins/org.jboss.tools.ws.ui/icons/obj16/jar_obj.gif
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbwsLibraryListFieldEditor.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntime.java
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeListConverter.java
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/IJBossWSFacetDataModelProperties.java
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/JBossWSFacetInstallDataModelProvider.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/JbossWSUIPlugin.java
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
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/JbossRuntimeListFieldEditor.java
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/PushButtonField.java
Log:
JBIDE-2262: add ui for users to add selected jars instead of adding all jars of runtime to
project classpath
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntime.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntime.java 2008-06-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntime.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -11,6 +11,9 @@
package org.jboss.tools.ws.core.classpath;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* @author Grid Qian
*/
@@ -21,11 +24,16 @@
String homeDir = null;
boolean defaultRt = false;
+
+ List<String> libraries;
+ private boolean userConfigClasspath;
+
/**
* Default constructor
*/
public JbossWSRuntime() {
+ libraries = new ArrayList<String>();
}
/**
@@ -84,5 +92,22 @@
public boolean isDefault() {
return defaultRt;
}
+
+ public List<String> getLibraries(){
+
+ return this.libraries;
+ }
+
+ public void setLibraries(List<String> libraries){
+ this.libraries = libraries;
+ }
+
+ public boolean isUserConfigClasspath(){
+ return this.userConfigClasspath;
+ }
+
+ public void setUserConfigClasspath(boolean userConfigClasspath){
+ this.userConfigClasspath = userConfigClasspath;
+ }
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeListConverter.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeListConverter.java 2008-06-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeListConverter.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -1,7 +1,10 @@
package org.jboss.tools.ws.core.classpath;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
@@ -18,11 +21,14 @@
*/
private static final String REGEXP_ESCAPE = "\\";
private static final String COMMA = ",";
+ private static final String LIBRARY_SEPARATOR = ";";
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";
+ private static final String USER_CONFIG_CLASSPATH = "userConfig";
+ private static final String LIBRARY = "libraries";
/**
* Load String to JbossWSRuntime map from String
@@ -55,13 +61,45 @@
rt.setHomeDir(value);
} else if (DEFAULT.equals(name)) {
rt.setDefault(Boolean.parseBoolean(value));
+ }else if(USER_CONFIG_CLASSPATH.equals(name)){
+ rt.setUserConfigClasspath(Boolean.parseBoolean(value));
+ }else if(LIBRARY.equals(name)){
+ if(value != null && !EMPTY_STRING.equals(value)){
+ rt.setLibraries(getLibrariesFromString(value));
+ }
}
+
}
result.put(rt.getName(), rt);
}
return result;
}
+
+ private List<String> getLibrariesFromString(String strLibraries){
+ List<String> libraries = new ArrayList<String>();
+ StringTokenizer st = new StringTokenizer(strLibraries, LIBRARY_SEPARATOR);
+ while(st.hasMoreTokens()){
+ String library = st.nextToken();
+ if(!libraries.contains(library)){
+ libraries.add(library);
+ }
+ }
+ return libraries;
+
+ }
+
+ private String convertListToString(List<String> libraries){
+ String strLib = "";
+ for(String library: libraries){
+ if("".equals(strLib)){
+ strLib = library;
+ }else{
+ strLib = strLib + LIBRARY_SEPARATOR + library;
+ }
+ }
+ return strLib;
+ }
/**
* Convert map String to JbossWSRUntime to string representation
@@ -84,6 +122,10 @@
buffer.append(FIELD_SEPARATOR).append(DEFAULT).append(
FIELD_SEPARATOR);
buffer.append(runtimes[i].isDefault());
+ buffer.append(FIELD_SEPARATOR).append(USER_CONFIG_CLASSPATH).append(FIELD_SEPARATOR);
+ buffer.append(runtimes[i].isUserConfigClasspath());
+ buffer.append(FIELD_SEPARATOR).append(LIBRARY).append(FIELD_SEPARATOR);
+ buffer.append(convertListToString(runtimes[i].getLibraries()));
if (i != runtimes.length - 1) {
buffer.append(COMMA);
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/IJBossWSFacetDataModelProperties.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/IJBossWSFacetDataModelProperties.java 2008-06-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/IJBossWSFacetDataModelProperties.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -30,11 +30,11 @@
String DEFAULT_VALUE_IS_SERVER_SUPPLIED = "1";
- QualifiedName PERSISTENCE_PROPERTY_QNAME_RUNTIME_NAME = new
QualifiedName(QUALIFIEDNAME_IDENTIFIER,
+ static QualifiedName PERSISTENCE_PROPERTY_QNAME_RUNTIME_NAME = new
QualifiedName(QUALIFIEDNAME_IDENTIFIER,
JBOSS_WS_RUNTIME_ID);
- QualifiedName PERSISTENCE_PROPERTY_RNTIME_LOCATION = new
QualifiedName(QUALIFIEDNAME_IDENTIFIER,
+ static QualifiedName PERSISTENCE_PROPERTY_RNTIME_LOCATION = new
QualifiedName(QUALIFIEDNAME_IDENTIFIER,
JBOSS_WS_RUNTIME_HOME);
- QualifiedName PERSISTENCE_PROPERTY_SERVER_SUPPLIED_RUNTIME = new QualifiedName(
+ static QualifiedName PERSISTENCE_PROPERTY_SERVER_SUPPLIED_RUNTIME = new QualifiedName(
QUALIFIEDNAME_IDENTIFIER,
PERSISTENT_PROPERTY_IS_SERVER_SUPPLIED_RUNTIME);
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/JBossWSFacetInstallDataModelProvider.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/JBossWSFacetInstallDataModelProvider.java 2008-06-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/JBossWSFacetInstallDataModelProvider.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -10,24 +10,14 @@
******************************************************************************/
package org.jboss.tools.ws.core.facet.delegate;
-import java.io.File;
-import java.io.IOException;
import java.util.Set;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider;
-/**
- * Data model provider for Seam facet wizard page
- *
- * @author eskimo
- *
- */
+
public class JBossWSFacetInstallDataModelProvider extends
FacetInstallDataModelProvider implements IJBossWSFacetDataModelProperties {
- private static final String EMPTY_STRING = "";
/**
* Returns set of facet properties for facet wizard page
Added: trunk/ws/plugins/org.jboss.tools.ws.ui/icons/obj16/jar_obj.gif
===================================================================
(Binary files differ)
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.ui/icons/obj16/jar_obj.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/JbossWSUIPlugin.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/JbossWSUIPlugin.java 2008-06-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/JbossWSUIPlugin.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -11,6 +11,7 @@
package org.jboss.tools.ws.ui;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -58,4 +59,8 @@
return plugin;
}
+ public static ImageDescriptor getImageDescriptor(String path) {
+ path = "icons/" + path; //$NON-NLS-1$
+ return AbstractUIPlugin.imageDescriptorFromPlugin("org.jboss.tools.ws.ui",
path); //$NON-NLS-1$
+ }
}
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-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUI.properties 2008-06-12
07:19:23 UTC (rev 8738)
@@ -32,4 +32,5 @@
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_Runtime_Check_Field_Default_Classpath=Configure JBoss Web Service Classpath
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-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUIMessages.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -59,6 +59,7 @@
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_Runtime_Check_Field_Default_Classpath;
public static String JBossWS_Preference_Page_Runtimes;
Modified:
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 2008-06-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/ButtonFieldEditor.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -24,6 +24,7 @@
public class ButtonFieldEditor extends BaseFieldEditor {
PushButtonField button= null;
+ int style;
private ButtonPressedAction buttonAction = new
ButtonPressedAction(JbossWSUIMessages.JBossWS_Button_Field_Editor_Browse) {
@Override
@@ -32,8 +33,9 @@
}
};
- public ButtonFieldEditor(String name, String label) {
+ public ButtonFieldEditor(String name, String label, int style) {
super(name, label, new Object());
+ this.style = style;
}
public ButtonFieldEditor(String name, ButtonPressedAction action, Object defaultValue)
{
@@ -69,7 +71,7 @@
@Override
public Object[] getEditorControls(Object composite) {
if(button==null && composite!=null) {
- button = new PushButtonField((Composite)composite,buttonAction);
+ button = new PushButtonField((Composite)composite, style, buttonAction);
setEnabled(isEnabled());
}
return new Control[]{button.getControl()};
Modified:
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 2008-06-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -400,6 +400,7 @@
private static final String SRT_NAME = "name";
private static final String SRT_HOMEDIR = "homeDir";
+ private static final String SRT_DEFAULT = "defaultClasspath";
private static final int GL_PARENT_COLUMNS = 1;
private static final int GL_CONTENT_COLUMNS = 3;
@@ -415,6 +416,8 @@
""); //$NON-NLS-1$
JbossWSRuntime current = null;
+
+ IFieldEditor jars = null;
public JbossWSRuntimeWizardPage(List<JbossWSRuntime> editedList) {
super(
@@ -444,9 +447,15 @@
name.addPropertyChangeListener(this);
homeDir.doFillIntoGrid(root);
homeDir.addPropertyChangeListener(this);
+
+ jars = new JbwsLibraryListFieldEditor("", "",
+ current);
+ jars.doFillIntoGrid(root);
+ jars.addPropertyChangeListener(this);
setPageComplete(false);
setControl(root);
}
+
/**
* Process evt: setup default values based on JbossWS Home folder and
@@ -495,13 +504,25 @@
}
}
+ JbossWSRuntime jarJbws = (JbossWSRuntime)jars.getValue();
if (current != null
&& current.getName().equals(name.getValueAsString())
- && current.getHomeDir().equals(homeDir.getValueAsString())) {
+ && current.getHomeDir().equals(homeDir.getValueAsString())
+ && current.isUserConfigClasspath() == jarJbws.isUserConfigClasspath()
+ && (!jarJbws.isUserConfigClasspath()
+ || hasSameLibraies(current.getLibraries(), jarJbws.getLibraries()))) {
+
setErrorMessage(null);
setPageComplete(false);
return;
}
+
+ if(jarJbws.isUserConfigClasspath()
+ && jarJbws.getLibraries().size() == 0){
+ setErrorMessage("The library must contian at least one jar.");
+ setPageComplete(false);
+ return;
+ }
if (homeDir.getValueAsString() == null
|| "".equals(homeDir.getValueAsString().trim())) { //$NON-NLS-1$
@@ -520,6 +541,14 @@
setPageComplete(true);
}
+ private boolean hasSameLibraies(List<String> lib1, List<String> lib2){
+ if(lib1.size() != lib2.size()) return false;
+ for(String jar: lib1){
+ if(!lib2.contains(jar)) return false;
+ }
+
+ return true;
+ }
/**
* Return JbossWS Runtime instance initialized by user input
*
@@ -529,6 +558,9 @@
JbossWSRuntime newRt = new JbossWSRuntime();
newRt.setName(name.getValueAsString());
newRt.setHomeDir(homeDir.getValueAsString());
+ JbossWSRuntime rt = (JbossWSRuntime)jars.getValue();
+ newRt.setLibraries(rt.getLibraries());
+ newRt.setUserConfigClasspath(rt.isUserConfigClasspath());
return newRt;
}
@@ -557,6 +589,8 @@
return editor;
}
+
+
public ButtonFieldEditor.ButtonPressedAction createSelectFolderAction(
String buttonName) {
return new ButtonFieldEditor.ButtonPressedAction(buttonName) {
@@ -693,13 +727,12 @@
@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.getHomeDir());
+ source.setUserConfigClasspath(rt.isUserConfigClasspath());
+ source.setLibraries(rt.getLibraries());
} else {
changed.put(rt, source);
if (source.isDefault()) {
@@ -980,7 +1013,7 @@
tableView.setSelection(new StructuredSelection(c));
}
}
- if (c != null & c.isDefault()) {
+ if (c != null && c.isDefault()) {
checkedElement = c;
}
setDefaultRuntime();
Modified:
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/JbossWSRuntimePreferencePage.java 2008-06-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -105,6 +105,8 @@
newName);
}
o.setDefault(c.isDefault());
+ o.setUserConfigClasspath(c.isUserConfigClasspath());
+ o.setLibraries(c.getLibraries());
}
jbossWSRuntimes.getChangedJbossWSRuntimes().clear();
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbwsLibraryListFieldEditor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbwsLibraryListFieldEditor.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbwsLibraryListFieldEditor.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -0,0 +1,588 @@
+/*******************************************************************************
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+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.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.jboss.tools.ws.core.classpath.JbossWSRuntime;
+import org.jboss.tools.ws.ui.JbossWSUIPlugin;
+import org.jboss.tools.ws.ui.messages.JbossWSUIMessages;
+
+/**
+ * @author Grid Qian
+ */
+public class JbwsLibraryListFieldEditor 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 TreeViewer listView = null;
+
+ private Composite root = null;
+
+ private ActionPanel actionPanel;
+
+ private JbossWSRuntime tempJbws;
+
+
+
+
+ private Group jarGroup;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Control for editing jbossWSRuntime list
+ *
+ * @param name
+ * String
+ * @param label
+ * String
+ * @param defaultValue
+ * Object
+ */
+ public JbwsLibraryListFieldEditor(String name, String label,
+ JbossWSRuntime jbws) {
+ super(name, label, jbws);
+ this.tempJbws = new JbossWSRuntime();
+ if(jbws != null){
+ this.tempJbws.setUserConfigClasspath(jbws.isUserConfigClasspath());
+ this.tempJbws.getLibraries().addAll(jbws.getLibraries());
+ }
+
+ }
+
+
+ public Object getValue(){
+ return this.tempJbws;
+ }
+ /**
+ * 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 GridLayout());
+
+ createCheckButton(root);
+
+ jarGroup = new Group(root, SWT.BORDER);
+ jarGroup.setText("Library Jars");
+ gd = new GridData(GridData.FILL_BOTH);
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = true;
+
+
+ jarGroup.setLayoutData(gd);
+ jarGroup.setLayout(new FormLayout());
+
+ createListView(jarGroup);
+ createActionBar(jarGroup);
+
+ FormData listData = new FormData();
+ listData.left = new FormAttachment(0, 5);
+ listData.right = new FormAttachment(actionPanel, -5);
+ listData.top = new FormAttachment(0, 5);
+ listData.bottom = new FormAttachment(100, -5);
+ listView.getControl().setLayoutData(listData);
+
+ 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);
+
+ setJarGroupStatus();
+ return new Control[] { root };
+ }
+
+ protected void createCheckButton(Composite parent){
+ final Button btnDefault = new Button(parent, SWT.CHECK);
+ btnDefault.setText(JbossWSUIMessages.JBossWS_Runtime_Check_Field_Default_Classpath);
+ GridData gd = new GridData();
+ gd.horizontalSpan = 2;
+ btnDefault.setLayoutData(gd);
+
+ btnDefault.setSelection(tempJbws.isUserConfigClasspath());
+ btnDefault.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent e) {
+ tempJbws.setUserConfigClasspath(btnDefault.getSelection());
+ setJarGroupStatus();
+ setValue(null);
+ }
+ });
+
+
+ }
+
+ protected void setJarGroupStatus(){
+ boolean isUserConfig = tempJbws.isUserConfigClasspath();
+ jarGroup.setEnabled(isUserConfig);
+ listView.getTree().setEnabled(isUserConfig);
+ actionPanel.setEnabled(isUserConfig);
+ }
+ @SuppressWarnings("unchecked")
+ protected void createListView(Composite parent) {
+ listView = new TreeViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ listView.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ listView.setContentProvider(new ITreeContentProvider() {
+
+ @SuppressWarnings("unchecked")
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof JbossWSRuntime) {
+ return ((JbossWSRuntime) inputElement).getLibraries().toArray();
+ } else {
+ throw new IllegalArgumentException(
+ JbossWSUIMessages.JBossWS_Runtime_List_Field_Editor_Inputelement_Must_Be
+ + JbossWSUIMessages.JBossWS_Runtime_List_Field_Editor_An_Instance_Of_List);
+ }
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ viewer.refresh();
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getParent(Object element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ });
+
+ listView.setLabelProvider(new ILabelProvider() {
+
+ Image jarImg;
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ public Image getImage(Object element) {
+ if (jarImg == null){
+ ImageDescriptor jarImgDesc =
JbossWSUIPlugin.getImageDescriptor("obj16/jar_obj.gif");
+ jarImg = jarImgDesc.createImage();
+ }
+ return jarImg;
+ }
+
+ public String getText(Object element) {
+ String fullName = (String)element;
+ File jarFile = new File(fullName);
+ return jarFile.getName() + " - " + jarFile.getParentFile().toString();
+ }
+ });
+
+
+ listView.setInput(getValue());
+
+ }
+
+ protected void createActionBar(Composite parent) {
+ actionPanel = new ActionPanel(parent, new BaseAction[] { new AddAction(),
+ new RemoveAction() });
+ listView.addSelectionChangedListener(actionPanel);
+ }
+
+
+
+ /**
+ * 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.Error_JBossWS_Basic_Editor_Composite);
+ Assert.isTrue(((Composite) parent).getLayout() instanceof GridLayout,
+ JbossWSUIMessages.Error_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);
+ }
+
+
+
+ /**
+ * 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 {
+
+ String[] jars = new String[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<String> rts = new ArrayList<String>();
+ for (Object jarfile : ((IStructuredSelection) selection).toArray()) {
+ rts.add((String) jarfile);
+ }
+ jars = rts.toArray(new String[] {});
+ } else {
+ jars = new String[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() {
+ FileDialog dialog = new FileDialog(Display.getCurrent()
+ .getActiveShell(), SWT.MULTI);
+ dialog.setFilterExtensions(new String[] { "*.jar;*.zip" });
+ String fileName = dialog.open();
+ String[] fileNames = dialog.getFileNames();
+ if (fileName != null) {
+ File filePath = new File(fileName);
+ filePath = filePath.getParentFile();
+ for (int i = 0; i < fileNames.length; i++) {
+ IPath path = new Path(filePath.getAbsolutePath())
+ .append(fileNames[i]);
+ if (!tempJbws.getLibraries().contains(path.toOSString())) {
+ tempJbws.getLibraries().add(path.toOSString());
+ }
+ }
+
+ listView.refresh();
+ setValue(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(jars.length > 0);
+ }
+
+ /**
+ * Remove all selected JbossWS Runtimes one by one
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ for (String jar : jars) {
+ tempJbws.getLibraries().remove(jar);
+ }
+ listView.refresh();
+ // just try to fire property change listener
+ setValue(null);
+ }
+
+
+ }
+}
\ No newline at end of file
Modified:
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 2008-06-12
07:13:33 UTC (rev 8737)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/PushButtonField.java 2008-06-12
07:19:23 UTC (rev 8738)
@@ -11,7 +11,6 @@
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;
@@ -34,8 +33,8 @@
}
- public PushButtonField(Composite composite, ButtonPressedAction listener) {
- button = new Button(composite,SWT.PUSH);
+ public PushButtonField(Composite composite, int style, ButtonPressedAction listener) {
+ button = new Button(composite, style);
button.setText(listener.getText());
button.addSelectionListener(listener);
}