Author: Grid.Qian
Date: 2008-06-06 01:01:35 -0400 (Fri, 06 Jun 2008)
New Revision: 8589
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage.java
Removed:
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
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/utils/JbossWSCoreUtils.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/preferences/JbossRuntimeListFieldEditor.java
Log:
JBIDE-2261: add validation for jboss ws runtime location
Modified: trunk/ws/plugins/org.jboss.tools.ws.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.core/META-INF/MANIFEST.MF 2008-06-05 23:33:44 UTC
(rev 8588)
+++ trunk/ws/plugins/org.jboss.tools.ws.core/META-INF/MANIFEST.MF 2008-06-06 05:01:35 UTC
(rev 8589)
@@ -12,9 +12,7 @@
org.eclipse.core.resources,
org.eclipse.jst.ws,
org.eclipse.jdt.core,
- org.eclipse.jdt.launching,
- org.eclipse.jst.jsf.core,
- org.eclipse.jst.jsf.ui
+ org.eclipse.jdt.launching
Eclipse-LazyStart: true
Bundle-Vendor: %PLUGIN_PROVIDER
Export-Package: org.jboss.tools.ws.core,
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/utils/JbossWSCoreUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/utils/JbossWSCoreUtils.java 2008-06-05
23:33:44 UTC (rev 8588)
+++
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/utils/JbossWSCoreUtils.java 2008-06-06
05:01:35 UTC (rev 8589)
@@ -28,13 +28,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jst.ws.internal.common.J2EEUtils;
import org.eclipse.osgi.util.NLS;
@@ -225,15 +220,7 @@
}
public static IPath getJbossWSRuntimePath(String runtimeName) {
- Map<String, JbossWSRuntime> runtimes = new HashMap<String,
JbossWSRuntime>();
- JbossWSRuntimeListConverter converter = new JbossWSRuntimeListConverter();
- IPreferenceStore ps = JbossWSCorePlugin.getDefault()
- .getPreferenceStore();
- String runtimeLocation = ps.getString(JbossWSCoreMessages.WS_LOCATION);
- runtimes = converter.getMap(runtimeLocation);
- if (runtimeLocation == null || runtimeLocation.equals("")) {
- return null;
- }
+ Map<String, JbossWSRuntime> runtimes = getJbossWSRutntimeMap();
if (runtimeName == null || runtimeName.equals("")) {
for (JbossWSRuntime rt : runtimes.values()) {
if (rt.isDefault()) {
@@ -247,5 +234,18 @@
}
return null;
}
+
+ public static Map<String, JbossWSRuntime> getJbossWSRutntimeMap(){
+ IPreferenceStore ps = JbossWSCorePlugin.getDefault()
+ .getPreferenceStore();
+ String runtimeLocation = ps.getString(JbossWSCoreMessages.WS_LOCATION);
+ if (runtimeLocation == null || runtimeLocation.equals("")) {
+ return new HashMap<String, JbossWSRuntime>();
+ }
+ Map<String, JbossWSRuntime> runtimes = new HashMap<String,
JbossWSRuntime>();
+ JbossWSRuntimeListConverter converter = new JbossWSRuntimeListConverter();
+ runtimes = converter.getMap(runtimeLocation);
+ return runtimes;
+ }
}
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-05
23:33:44 UTC (rev 8588)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JbossWSUI.properties 2008-06-06
05:01:35 UTC (rev 8589)
@@ -55,7 +55,7 @@
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=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
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-05
23:33:44 UTC (rev 8588)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java 2008-06-06
05:01:35 UTC (rev 8589)
@@ -56,6 +56,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.TableColumn;
import org.jboss.tools.ws.ui.messages.JbossWSUIMessages;
+import org.jboss.tools.ws.ui.utils.UIUtils;
import org.jboss.tools.ws.core.classpath.JbossWSRuntime;
/**
@@ -434,10 +435,10 @@
root.setLayoutData(dg);
GridLayout gl = new GridLayout(GL_CONTENT_COLUMNS, false);
root.setLayout(gl);
+ name.doFillIntoGrid(root);
+ name.addPropertyChangeListener(this);
homeDir.doFillIntoGrid(root);
homeDir.addPropertyChangeListener(this);
- name.doFillIntoGrid(root);
- name.addPropertyChangeListener(this);
setPageComplete(false);
setControl(root);
}
@@ -452,7 +453,8 @@
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if ("homeDir".equals(evt.getPropertyName())) {
if (name.getValueAsString() == null
- || "".equals(name.getValueAsString().trim())) {
+ || "".equals(name.getValueAsString().trim())
+ || this.getErrorMessage() != null) {
String homeDirName = homeDir.getValueAsString();
if (homeDirName != null && !"".equals(homeDirName.trim())) {
File folder = new File(homeDirName);
@@ -503,6 +505,12 @@
return;
}
+ if (!runtimeExist(homeDir.getValueAsString())) {
+ setErrorMessage(JbossWSUIMessages.LABEL_JBOSSWS_RUNTIME_LOAD_ERROR);
+ setPageComplete(false);
+ return;
+ }
+
setErrorMessage(null);
setPageComplete(true);
}
@@ -562,6 +570,21 @@
}
};
}
+
+ 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;
+ }
}
/**
@@ -599,7 +622,7 @@
}
/**
- * Wizard for editing JbossWS Runrtime parameters: name, version and path to
+ * Wizard for editing JbossWS Runtime parameters: name and path to
* home folder
*
*/
@@ -657,7 +680,7 @@
}
if (added.contains(source) || changed.containsKey(source)) {
source.setName(rt.getName());
- source.setHomeDir(rt.getName());
+ source.setHomeDir(rt.getHomeDir());
} else {
changed.put(rt, source);
int i = value.indexOf(source);
Deleted:
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-05
23:33:44 UTC (rev 8588)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage.java 2008-06-06
05:01:35 UTC (rev 8589)
@@ -1,201 +0,0 @@
-/*******************************************************************************
- * 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 JbossWSRuntimePreferencePage 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;
- }
-
-}
Copied:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage.java
(from rev 8556,
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/JbossWSRuntimePreferencePage.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage.java 2008-06-06
05:01:35 UTC (rev 8589)
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.jboss.tools.ws.core.classpath.JbossWSRuntime;
+import org.jboss.tools.ws.core.classpath.JbossWSRuntimeManager;
+import org.jboss.tools.ws.ui.messages.JbossWSUIMessages;
+
+/**
+ * @author Grid Qian
+ */
+public class JbossWSRuntimePreferencePage extends PreferencePage implements
IWorkbenchPreferencePage {
+
+ public JbossWSRuntimePreferencePage() {
+ super();
+ noDefaultAndApplyButton();
+ }
+
+ private static final int COLUMNS = 3;
+
+ JbossRuntimeListFieldEditor jbossWSRuntimes = new JbossRuntimeListFieldEditor(
+ "rtlist", JbossWSUIMessages.JBOSSWS_PREFERENCE_PAGE_RUNTIMES, new
ArrayList<JbossWSRuntime>(Arrays.asList(JbossWSRuntimeManager.getInstance().getRuntimes())));
//$NON-NLS-1$
+
+ /**
+ * Create contents of JbossWS preferences page. JbossWSRuntime list editor is
+ * created
+ *
+ * @return Control
+ */
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite root = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(COLUMNS, false);
+ root.setLayout(gl);
+ jbossWSRuntimes.doFillIntoGrid(root);
+
+ return root;
+ }
+
+ /**
+ * Inherited from IWorkbenchPreferencePage
+ *
+ * @param workbench
+ * {@link IWorkbench}
+ *
+ */
+ public void init(IWorkbench workbench) {
+ }
+
+ /**
+ * Save JbossWSRuntime list
+ */
+ @Override
+ protected void performApply() {
+ for (JbossWSRuntime rt : jbossWSRuntimes.getAddedJbossWSRuntimes()) {
+ JbossWSRuntimeManager.getInstance().addRuntime(rt);
+ }
+ jbossWSRuntimes.getAddedJbossWSRuntimes().clear();
+ for (JbossWSRuntime rt : jbossWSRuntimes.getRemoved()) {
+ JbossWSRuntimeManager.getInstance().removeRuntime(rt);
+ }
+ jbossWSRuntimes.getRemoved().clear();
+ JbossWSRuntime defaultRuntime = jbossWSRuntimes.getDefaultJbossWSRuntime();
+ // reset default runtime
+ for (JbossWSRuntime jbossWSRuntime : JbossWSRuntimeManager.getInstance().getRuntimes())
{
+ jbossWSRuntime.setDefault(false);
+ }
+ // set deafult runtime
+ defaultRuntime.setDefault(true);
+ jbossWSRuntimes.setDefaultJbossWSRuntime(null);
+ Map<JbossWSRuntime, JbossWSRuntime> changed =
jbossWSRuntimes.getChangedJbossWSRuntimes();
+ for (JbossWSRuntime c : changed.keySet()) {
+ JbossWSRuntime o = changed.get(c);
+ o.setHomeDir(c.getHomeDir());
+ String oldName = o.getName();
+ String newName = c.getName();
+ if (!oldName.equals(newName)) {
+ JbossWSRuntimeManager.getInstance().changeRuntimeName(oldName, newName);
+ }
+ }
+ jbossWSRuntimes.getChangedJbossWSRuntimes().clear();
+
+ JbossWSRuntimeManager.getInstance().save();
+ }
+
+ /**
+ * Restore original preferences values
+ */
+ @Override
+ protected void performDefaults() {
+ setValid(true);
+ setMessage(null);
+ performApply();
+ }
+
+ /**
+ * See {@link PreferencePage} for details
+ *
+ * @return Boolean
+ */
+ @Override
+ public boolean performOk() {
+ performApply();
+ return super.performOk();
+ }
+}
Deleted:
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/JbossWSRuntimePreferencePage2.java 2008-06-05
23:33:44 UTC (rev 8588)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossWSRuntimePreferencePage2.java 2008-06-06
05:01:35 UTC (rev 8589)
@@ -1,201 +0,0 @@
-/*******************************************************************************
- * 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;
- }
-
-}