Author: snjeza
Date: 2010-09-07 19:12:44 -0400 (Tue, 07 Sep 2010)
New Revision: 24781
Added:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimeDialog.java
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeLocator.java
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/ServerDefinition.java
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/bean/ServerType.java
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimePreferencePage.java
Log:
https://jira.jboss.org/browse/JBIDE-6913 Jboss Runtime recognition - improvements
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeLocator.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeLocator.java 2010-09-07
18:26:44 UTC (rev 24780)
+++
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeLocator.java 2010-09-07
23:12:44 UTC (rev 24781)
@@ -26,7 +26,7 @@
import org.jboss.tools.runtime.bean.ServerBeanLoader;
import org.jboss.tools.runtime.bean.ServerType;
-public class JBossRuntimeLocator extends RuntimeLocatorDelegate {
+public class JBossRuntimeLocator {
public static final String JBPM3 = "jBPM3";
@@ -36,24 +36,26 @@
public JBossRuntimeLocator() {
}
+
+ public List<ServerDefinition> searchForRuntimes(String path, IProgressMonitor
monitor) {
+ return searchForRuntimes(new Path(path), monitor);
+ }
- @Override
- public void searchForRuntimes(IPath path, IRuntimeSearchListener listener,
- IProgressMonitor monitor) {
+ public List<ServerDefinition> searchForRuntimes(IPath path, IProgressMonitor
monitor) {
ServerBeanLoader loader = new ServerBeanLoader();
List<ServerDefinition> serverDefinitions = new
ArrayList<ServerDefinition>();
- searchForRuntimes(serverDefinitions, path, loader, 4, monitor);
- JBossRuntimeStartup runtimeStartup = new JBossRuntimeStartup();
- runtimeStartup.initializeRuntimes(serverDefinitions);
+ return searchForRuntimes(serverDefinitions, path, loader, 4, monitor);
}
- public void searchForRuntimes(String path, IProgressMonitor monitor) {
- searchForRuntimes(new Path(path), null, monitor);
- }
-
- private void searchForRuntimes(List<ServerDefinition> serverDefinitions, IPath
path, ServerBeanLoader loader, int depth, IProgressMonitor monitor) {
+ private List<ServerDefinition> searchForRuntimes(List<ServerDefinition>
serverDefinitions, IPath path, ServerBeanLoader loader, int depth, IProgressMonitor
monitor) {
+ if (monitor.isCanceled()) {
+ return serverDefinitions;
+ }
File[] children = null;
if (path != null) {
+ monitor.setTaskName("Searching " + path.toOSString());
+ }
+ if (path != null) {
File root = path.toFile();
ServerBean serverBean = loader.loadFromLocation(root);
@@ -106,17 +108,16 @@
children = File.listRoots();
}
if (depth == 0) {
- return;
+ return serverDefinitions;
}
if( children != null ) {
- monitor.beginTask("Searching for JBoss runtime...", children.length);
//$NON-NLS-1$
for( int i = 0; i < children.length; i++ ) {
if( children[i].isDirectory()) {
searchForRuntimes(serverDefinitions, new Path(children[i].getAbsolutePath()),
loader, --depth, monitor);
}
}
}
- monitor.done();
+ return serverDefinitions;
}
/**
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/ServerDefinition.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/ServerDefinition.java 2010-09-07
18:26:44 UTC (rev 24780)
+++
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/ServerDefinition.java 2010-09-07
23:12:44 UTC (rev 24781)
@@ -24,6 +24,7 @@
private String version;
private String type;
private File location;
+ private boolean enabled = true;
public ServerDefinition(String name, String version, String type,
File location) {
@@ -118,5 +119,13 @@
return "ServerDefinition [name=" + name + ", version=" + version
+ ", type=" + type + ", location=" + location + "]";
}
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
}
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/bean/ServerType.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/bean/ServerType.java 2010-09-07
18:26:44 UTC (rev 24780)
+++
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/bean/ServerType.java 2010-09-07
23:12:44 UTC (rev 24781)
@@ -51,7 +51,7 @@
"EAP",
"Enterprise Application Platform",
JBOSS_AS_PATH + File.separatorChar + BIN_PATH+ File.separatorChar + TWIDDLE_JAR_NAME,
- new String[]{"4.2","4.3","5.0"}, new
EAPServerTypeCondition());
+ new String[]{"4.2","4.3","5.0","5.1"}, new
EAPServerTypeCondition());
public static final ServerType SOAP = new ServerType(
"SOA-P",
Added:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimeDialog.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimeDialog.java
(rev 0)
+++
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimeDialog.java 2010-09-07
23:12:44 UTC (rev 24781)
@@ -0,0 +1,153 @@
+package org.jboss.tools.runtime.preferences;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+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.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.jboss.tools.runtime.ServerDefinition;
+import org.omg.CORBA.DefinitionKind;
+
+public class RuntimeDialog extends Dialog {
+
+ private List<ServerDefinition> serverDefinitions;
+ private String path;
+ private CheckboxTableViewer tableViewer;
+
+ public RuntimeDialog(Shell parentShell, List<ServerDefinition> serverDefinitions ,
String path) {
+ super(parentShell);
+ setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER
+ | SWT.MODELESS | SWT.RESIZE | getDefaultOrientation());
+ this.serverDefinitions = serverDefinitions;
+ this.path = path;
+
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite contents = new Composite(area, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 400;
+ gd.widthHint = 500;
+ contents.setLayoutData(gd);
+ contents.setLayout(new GridLayout());
+ getShell().setText("JBoss Runtimes");
+ applyDialogFont(contents);
+ initializeDialogUnits(area);
+
+ Label label = new Label(contents, SWT.NULL);
+ String runtime = (serverDefinitions.size() == 1) ? "runtime" :
"runtimes";
+ label.setText("The search found " + serverDefinitions.size() + " "
+ runtime + " while searching " + path + ".");
+ tableViewer = CheckboxTableViewer.newCheckList(contents, SWT.V_SCROLL
+ | SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
+ Table table = tableViewer.getTable();
+ gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 100;
+ table.setLayoutData(gd);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ String[] columnNames = new String[] { "Name", "Version",
"Type", "Location"};
+ int[] columnWidths = new int[] { 140, 50, 50, 245};
+
+ for (int i = 0; i < columnNames.length; i++) {
+ TableColumn tc = new TableColumn(table, SWT.LEFT);
+ tc.setText(columnNames[i]);
+ tc.setWidth(columnWidths[i]);
+ }
+
+ tableViewer.setLabelProvider(new RuntimeLabelProvider());
+ tableViewer.setContentProvider(new RuntimeContentProvider(serverDefinitions));
+ tableViewer.setInput(serverDefinitions);
+ for (ServerDefinition definition:serverDefinitions) {
+ tableViewer.setChecked(definition, definition.isEnabled());
+ }
+ tableViewer.addCheckStateListener(new ICheckStateListener() {
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ ServerDefinition definition = (ServerDefinition) event.getElement();
+ definition.setEnabled(!definition.isEnabled());
+ boolean enableOk = false;
+ for (ServerDefinition serverDefinition:serverDefinitions) {
+ if (serverDefinition.isEnabled()) {
+ enableOk = true;
+ }
+ }
+ getButton(IDialogConstants.OK_ID).setEnabled(enableOk);
+ }
+ });
+ return area;
+ }
+
+ private class RuntimeLabelProvider extends LabelProvider implements
+ ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof ServerDefinition) {
+ ServerDefinition definition = (ServerDefinition) element;
+ if (columnIndex == 0) {
+ return definition.getName();
+ }
+ if (columnIndex == 1) {
+ return definition.getVersion();
+ }
+ if (columnIndex == 2) {
+ return definition.getType();
+ }
+ if (columnIndex == 3) {
+ File location = definition.getLocation();
+ if (location != null) {
+ return definition.getLocation().getAbsolutePath();
+ }
+ }
+ }
+ return null;
+ }
+ }
+
+ private class RuntimeContentProvider implements IStructuredContentProvider {
+
+ private List<ServerDefinition> serverDefinitions;
+
+ public RuntimeContentProvider(List<ServerDefinition> serverDefinitions) {
+ this.serverDefinitions = serverDefinitions;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return serverDefinitions.toArray();
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ serverDefinitions = (List<ServerDefinition>) newInput;
+ }
+
+ }
+
+}
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimePreferencePage.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimePreferencePage.java 2010-09-07
18:26:44 UTC (rev 24780)
+++
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimePreferencePage.java 2010-09-07
23:12:44 UTC (rev 24781)
@@ -14,19 +14,23 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.layout.PixelConverter;
-import org.eclipse.jface.preference.PreferenceDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -59,6 +63,8 @@
import org.jboss.tools.jbpm.preferences.PreferencesManager;
import org.jboss.tools.runtime.Activator;
import org.jboss.tools.runtime.JBossRuntimeLocator;
+import org.jboss.tools.runtime.JBossRuntimeStartup;
+import org.jboss.tools.runtime.ServerDefinition;
/**
* @author Snjeza
@@ -77,6 +83,8 @@
protected Map<String, Object> map = new HashMap<String, Object>();
+ private List<ServerDefinition> serverDefinitions;
+
/*
* (non-Javadoc)
*
@@ -286,10 +294,7 @@
link.setText(text);
link.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- PreferenceDialog dialog =
PreferencesUtil.createPreferenceDialogOn(getShell(),preferencesId, new String[]
{preferencesId},null);
- if (dialog != null) {
- dialog.open();
- }
+ PreferencesUtil.createPreferenceDialogOn(getShell(),preferencesId, null, null);
}
});
}
@@ -306,13 +311,51 @@
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setMessage("Search for JBoss Runtimes");
dialog.setFilterPath(lastUsedPath);
- String path = dialog.open();
+ final String path = dialog.open();
if (path == null) {
return;
}
dialogSettings.put(LASTPATH, path);
- JBossRuntimeLocator locator = new JBossRuntimeLocator();
- locator.searchForRuntimes(path, new NullProgressMonitor());
+
+ IRunnableWithProgress op = new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) {
+ JBossRuntimeLocator locator = new JBossRuntimeLocator();
+ serverDefinitions = locator.searchForRuntimes(path, monitor);
+
+ }
+ };
+
+ try {
+ serverDefinitions = null;
+ new ProgressMonitorDialog(getShell()).run(true, true, op);
+ } catch (InvocationTargetException e) {
+ Activator.log(e);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+
+ if (serverDefinitions == null || serverDefinitions.size() == 0) {
+ MessageDialog.openInformation(null, "Search for JBoss Runtimes",
+ "The search found 0 runtimes while searching "
+ + path + ".");
+ } else {
+ RuntimeDialog runtimeDialog = new RuntimeDialog(getShell(),
+ serverDefinitions, path);
+ int ok = runtimeDialog.open();
+ if (ok == Window.OK) {
+ Iterator<ServerDefinition> iterator = serverDefinitions.iterator();
+ while (iterator.hasNext()) {
+ ServerDefinition definition = iterator.next();
+ if (!definition.isEnabled()) {
+ iterator.remove();
+ }
+ }
+ JBossRuntimeStartup runtimeStartup = new JBossRuntimeStartup();
+ runtimeStartup.initializeRuntimes(serverDefinitions);
+ }
+ }
+
}
/**