[jboss-svn-commits] JBL Code SVN: r23734 - in labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin: src/main/java/org/drools/eclipse/preferences and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 5 21:16:43 EST 2008
Author: KrisVerlaenen
Date: 2008-11-05 21:16:43 -0500 (Wed, 05 Nov 2008)
New Revision: 23734
Added:
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsProjectPreferencePage.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimeDialog.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimesBlock.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimesPreferencePage.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsRuntimeManager.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/wizard/project/NewDroolsProjectRuntimeWizardPage.java
Removed:
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsBuildPathPropertyPage.java
Modified:
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/IDroolsConstants.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsClasspathContainer.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsClasspathContainerInitializer.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/wizard/project/NewDroolsProjectWizard.java
Log:
JBRULES-1833: Support for multiple Drools Runtimes
- supporting multiple Drools Runtimes
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml 2008-11-06 02:02:55 UTC (rev 23733)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml 2008-11-06 02:16:43 UTC (rev 23734)
@@ -206,10 +206,27 @@
<extension point = "org.eclipse.ui.preferencePages">
<page id="org.drools.eclipse.preferences.DroolsPreferencePage"
class="org.drools.eclipse.preferences.DroolsPreferencePage"
- name="Drools Preferences">
+ name="Drools">
</page>
+ <page name="Installed Drools Runtimes"
+ category="org.drools.eclipse.preferences.DroolsPreferencePage"
+ class="org.drools.eclipse.preferences.DroolsRuntimesPreferencePage"
+ id="org.drools.eclipse.preferences.DroolsRuntimesPreferencePage">
+ </page>
</extension>
+ <extension point="org.eclipse.ui.propertyPages">
+ <page name="Drools"
+ class="org.drools.eclipse.preferences.DroolsProjectPreferencePage"
+ id="org.drools.eclipse.preferences.DroolsProjectPreferencePage">
+ <enabledWhen>
+ <adapt type="org.eclipse.core.resources.IProject">
+ <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.jdt.core.javanature"/>
+ </adapt>
+ </enabledWhen>
+ </page>
+ </extension>
+
<extension
point="org.eclipse.ui.perspectives">
<perspective
Deleted: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsBuildPathPropertyPage.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsBuildPathPropertyPage.java 2008-11-06 02:02:55 UTC (rev 23733)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsBuildPathPropertyPage.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -1,5 +0,0 @@
-package org.drools.eclipse.preferences;
-
-public class DroolsBuildPathPropertyPage {
-
-}
Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsProjectPreferencePage.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsProjectPreferencePage.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsProjectPreferencePage.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -0,0 +1,99 @@
+package org.drools.eclipse.preferences;
+
+import java.io.ByteArrayInputStream;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.preferences.DroolsRuntimesBlock.DroolsRuntime;
+import org.drools.eclipse.util.DroolsRuntimeManager;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage;
+import org.eclipse.swt.SWT;
+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.Label;
+
+public class DroolsProjectPreferencePage extends PropertyAndPreferencePage {
+
+ public static final String PREF_ID= "org.drools.eclipse.preferences.DroolsRuntimesPreferencePage";
+ public static final String PROP_ID= "org.drools.eclipse.preferences.DroolsProjectPreferencePage";
+
+ private Combo droolsRuntimeCombo;
+
+ public DroolsProjectPreferencePage() {
+ setTitle("Drools Project Preferences");
+ }
+
+ protected Control createPreferenceContent(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ composite.setLayout(gridLayout);
+
+ Label nameLabel = new Label(composite, SWT.NONE);
+ nameLabel.setText("Drools Runtime: ");
+ droolsRuntimeCombo = new Combo(composite, SWT.LEFT);
+ DroolsRuntime[] runtimes = DroolsRuntimeManager.getDroolsRuntimes();
+ int selection = -1;
+ String currentRuntime = DroolsRuntimeManager.getDroolsRuntime(getProject());
+ for (int i = 0; i < runtimes.length; i++) {
+ droolsRuntimeCombo.add(runtimes[i].getName());
+ if (runtimes[i].getName().equals(currentRuntime)) {
+ selection = i;
+ }
+ }
+ if (selection != -1) {
+ droolsRuntimeCombo.select(selection);
+ }
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ droolsRuntimeCombo.setLayoutData(gridData);
+ return composite;
+ }
+
+ protected String getPreferencePageID() {
+ return PREF_ID;
+ }
+
+ protected String getPropertyPageID() {
+ return PROP_ID;
+ }
+
+ protected boolean hasProjectSpecificOptions(IProject project) {
+ return project.getFile(".drools.runtime").exists();
+ }
+
+ public boolean performOk() {
+ try {
+ IFile file = getProject().getFile(".drools.runtime");
+ if (useProjectSettings()) {
+ String runtime = "<runtime>"
+ + droolsRuntimeCombo.getItem(droolsRuntimeCombo.getSelectionIndex())
+ + "</runtime>";
+ if (!file.exists()) {
+ file.create(new ByteArrayInputStream(runtime.getBytes()), true, null);
+ } else {
+ file.setContents(new ByteArrayInputStream(runtime.getBytes()), true, false, null);
+ }
+ } else {
+ if (file.exists()) {
+ file.delete(true, null);
+ }
+ }
+ getProject().close(null);
+ getProject().open(null);
+ } catch (Throwable t) {
+ DroolsEclipsePlugin.log(t);
+ return false;
+ }
+ return super.performOk();
+ }
+
+}
Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimeDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimeDialog.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimeDialog.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -0,0 +1,174 @@
+package org.drools.eclipse.preferences;
+
+import java.io.File;
+
+import org.drools.eclipse.preferences.DroolsRuntimesBlock.DroolsRuntime;
+import org.drools.eclipse.util.DroolsRuntimeManager;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+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.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class DroolsRuntimeDialog extends Dialog {
+
+ private DroolsRuntime runtime;
+ private Text nameText;
+ private Text pathText;
+ private Listener textModifyListener = new Listener() {
+ public void handleEvent(Event e) {
+ boolean valid = validate();
+ getButton(IDialogConstants.OK_ID).setEnabled(valid);
+ }
+ };
+
+ public DroolsRuntimeDialog(Shell parent) {
+ super(parent);
+ setBlockOnOpen(true);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ composite.setLayout(gridLayout);
+
+ Label label = new Label(composite, SWT.WRAP);
+ label.setFont(composite.getFont());
+ label.setText("Either select an existing Drools Runtime on your file system or create a new one.");
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = 3;
+ gridData.widthHint = 450;
+ label.setLayoutData(gridData);
+
+ Label nameLabel = new Label(composite, SWT.NONE);
+ nameLabel.setText("Name: ");
+ nameText = new Text(composite, SWT.NONE);
+ nameText.setText(runtime == null || runtime.getName() == null ? "" : runtime.getName());
+ nameText.addListener(SWT.Modify, textModifyListener);
+ gridData = new GridData();
+ gridData.horizontalSpan = 2;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ nameText.setLayoutData(gridData);
+
+ label = new Label(composite, SWT.NONE);
+ label.setText("Path: ");
+ pathText = new Text(composite, SWT.NONE);
+ pathText.setText(runtime == null || runtime.getPath() == null ? "" : runtime.getPath());
+ pathText.addListener(SWT.Modify, textModifyListener);
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ pathText.setLayoutData(gridData);
+ Button selectButton = new Button(composite, SWT.PUSH | SWT.LEFT);
+ selectButton.setText("Browse ...");
+ gridData = new GridData();
+ selectButton.setLayoutData(gridData);
+ selectButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ browse();
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ Button createButton = new Button(composite, SWT.PUSH | SWT.LEFT);
+ createButton.setText("Create a new Drools 5 Runtime ...");
+ gridData = new GridData();
+ gridData.horizontalSpan = 2;
+ createButton.setLayoutData(gridData);
+ createButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ createRuntime();
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ return composite;
+ }
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Drools Runtime");
+ }
+
+ protected Point getInitialSize() {
+ return new Point(500, 250);
+ }
+
+ public void setDroolsRuntime(DroolsRuntime runtime) {
+ this.runtime = runtime;
+ }
+
+ private boolean validate() {
+ String name = nameText.getText();
+ if (name == null || "".equals(name.trim())) {
+ return false;
+ }
+ String location = pathText.getText();
+ if (location != null) {
+ File file = new File(location);
+ if (file.exists() && file.isDirectory()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void browse() {
+ String selectedDirectory = null;
+ String dirName = pathText.getText();
+
+ DirectoryDialog dialog = new DirectoryDialog(getShell());
+ dialog.setMessage("Select the Drools runtime directory.");
+ dialog.setFilterPath(dirName);
+ selectedDirectory = dialog.open();
+
+ if (selectedDirectory != null) {
+ pathText.setText(selectedDirectory);
+ }
+ }
+
+ private void createRuntime() {
+ DirectoryDialog dialog = new DirectoryDialog(getShell());
+ dialog.setMessage("Select the new Drools 5 runtime directory.");
+ String selectedDirectory = dialog.open();
+
+ if (selectedDirectory != null) {
+ DroolsRuntimeManager.createDefaultRuntime(selectedDirectory);
+ nameText.setText("Drools 5.0.0 runtime");
+ pathText.setText(selectedDirectory);
+ }
+ }
+
+ public DroolsRuntime getResult() {
+ return runtime;
+ }
+
+ protected void okPressed() {
+ runtime = new DroolsRuntime();
+ runtime.setName(nameText.getText());
+ runtime.setPath(pathText.getText());
+ super.okPressed();
+ }
+
+}
Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimesBlock.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimesBlock.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimesBlock.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -0,0 +1,346 @@
+package org.drools.eclipse.preferences;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.jdt.internal.debug.ui.SWTFactory;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+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.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class DroolsRuntimesBlock implements ISelectionProvider {
+
+ private Composite fControl;
+ private List<DroolsRuntime> droolsRuntimes = new ArrayList<DroolsRuntime>();
+ private CheckboxTableViewer droolsRuntimesList;
+ private Button fAddButton;
+ private Button fRemoveButton;
+ private Button fEditButton;
+ private ListenerList fSelectionListeners = new ListenerList();
+ private ISelection fPrevSelection = new StructuredSelection();
+ private Table fTable;
+
+ class DroolsRuntimesContentProvider implements IStructuredContentProvider {
+ public Object[] getElements(Object input) {
+ return droolsRuntimes.toArray();
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ public void dispose() {
+ }
+ }
+
+ class DroolsRuntimesLabelProvider extends LabelProvider implements ITableLabelProvider {
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof DroolsRuntime) {
+ DroolsRuntime runtime = (DroolsRuntime) element;
+ switch(columnIndex) {
+ case 0:
+ return runtime.getName();
+ case 1:
+ return runtime.getPath();
+ }
+ }
+ return element.toString();
+ }
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ fSelectionListeners.add(listener);
+ }
+
+ public ISelection getSelection() {
+ return new StructuredSelection(droolsRuntimesList.getCheckedElements());
+ }
+
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ fSelectionListeners.remove(listener);
+ }
+
+ public void setSelection(ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ if (!selection.equals(fPrevSelection)) {
+ fPrevSelection = selection;
+ Object runtime = ((IStructuredSelection)selection).getFirstElement();
+ if (runtime == null) {
+ droolsRuntimesList.setCheckedElements(new Object[0]);
+ } else {
+ droolsRuntimesList.setCheckedElements(new Object[]{runtime});
+ droolsRuntimesList.reveal(runtime);
+ }
+ fireSelectionChanged();
+ }
+ }
+ }
+
+ private void fireSelectionChanged() {
+ SelectionChangedEvent event = new SelectionChangedEvent(this, getSelection());
+ Object[] listeners = fSelectionListeners.getListeners();
+ for (int i = 0; i < listeners.length; i++) {
+ ISelectionChangedListener listener = (ISelectionChangedListener)listeners[i];
+ listener.selectionChanged(event);
+ }
+ }
+
+ public void createControl(Composite ancestor) {
+ Font font = ancestor.getFont();
+ Composite parent= SWTFactory.createComposite(ancestor, font, 2, 1, GridData.FILL_BOTH);
+ fControl = parent;
+
+ SWTFactory.createLabel(parent, "Installed Drools Runtimes", 2);
+
+ fTable = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 250;
+ gd.widthHint = 350;
+ fTable.setLayoutData(gd);
+ fTable.setFont(font);
+ fTable.setHeaderVisible(true);
+ fTable.setLinesVisible(true);
+
+ TableColumn column = new TableColumn(fTable, SWT.NULL);
+ column.setText("Name");
+ int defaultwidth = 350/2 +1;
+ column.setWidth(defaultwidth);
+
+ column = new TableColumn(fTable, SWT.NULL);
+ column.setText("Location");
+ column.setWidth(defaultwidth);
+
+ droolsRuntimesList = new CheckboxTableViewer(fTable);
+ droolsRuntimesList.setLabelProvider(new DroolsRuntimesLabelProvider());
+ droolsRuntimesList.setContentProvider(new DroolsRuntimesContentProvider());
+
+ droolsRuntimesList.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent evt) {
+ enableButtons();
+ }
+ });
+
+ droolsRuntimesList.addCheckStateListener(new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if (event.getChecked()) {
+ setDefaultDroolsRuntime((DroolsRuntime) event.getElement());
+ } else {
+ setDefaultDroolsRuntime(null);
+ }
+ }
+ });
+
+ droolsRuntimesList.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent e) {
+ if (!droolsRuntimesList.getSelection().isEmpty()) {
+ editDroolsRuntime();
+ }
+ }
+ });
+ fTable.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent event) {
+ if (event.character == SWT.DEL && event.stateMask == 0) {
+ if (fRemoveButton.isEnabled()){
+ removeDroolsRuntimes();
+ }
+ }
+ }
+ });
+
+ Composite buttons = SWTFactory.createComposite(parent, font, 1, 1, GridData.VERTICAL_ALIGN_BEGINNING, 0, 0);
+
+ fAddButton = SWTFactory.createPushButton(buttons, "Add...", null);
+ fAddButton.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event evt) {
+ addDroolsRuntime();
+ }
+ });
+
+ fEditButton= SWTFactory.createPushButton(buttons, "Edit...", null);
+ fEditButton.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event evt) {
+ editDroolsRuntime();
+ }
+ });
+
+ fRemoveButton= SWTFactory.createPushButton(buttons, "Remove", null);
+ fRemoveButton.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event evt) {
+ removeDroolsRuntimes();
+ }
+ });
+
+ SWTFactory.createVerticalSpacer(parent, 1);
+
+ enableButtons();
+ fAddButton.setEnabled(true);
+ }
+
+ private void enableButtons() {
+ IStructuredSelection selection = (IStructuredSelection) droolsRuntimesList.getSelection();
+ int selectionCount= selection.size();
+ fEditButton.setEnabled(selectionCount == 1);
+ if (selectionCount > 0 && selectionCount < droolsRuntimesList.getTable().getItemCount()) {
+ fRemoveButton.setEnabled(true);
+ } else {
+ fRemoveButton.setEnabled(false);
+ }
+ }
+
+ public Control getControl() {
+ return fControl;
+ }
+
+ public void setDroolsRuntimes(DroolsRuntime[] runtimes) {
+ droolsRuntimes.clear();
+ for (int i = 0; i < runtimes.length; i++) {
+ droolsRuntimes.add(runtimes[i]);
+ }
+ droolsRuntimesList.setInput(droolsRuntimes);
+ droolsRuntimesList.refresh();
+ }
+
+ public DroolsRuntime[] getDroolsRuntimes() {
+ DroolsRuntime selected = getDefaultDroolsRuntime();
+ for (DroolsRuntime runtime: droolsRuntimes) {
+ runtime.setDefault(runtime.equals(selected));
+ }
+ return droolsRuntimes.toArray(new DroolsRuntime[droolsRuntimes.size()]);
+ }
+
+ private void addDroolsRuntime() {
+ DroolsRuntimeDialog dialog = new DroolsRuntimeDialog(getShell());
+ if (dialog.open() == Window.OK) {
+ DroolsRuntime result = dialog.getResult();
+ if (result != null) {
+ droolsRuntimes.add(result);
+ droolsRuntimesList.refresh();
+ droolsRuntimesList.setSelection(new StructuredSelection(result));
+ }
+ }
+ }
+
+ private void editDroolsRuntime() {
+ IStructuredSelection selection= (IStructuredSelection) droolsRuntimesList.getSelection();
+ DroolsRuntime runtime = (DroolsRuntime) selection.getFirstElement();
+ if (runtime == null) {
+ return;
+ }
+ DroolsRuntimeDialog dialog = new DroolsRuntimeDialog(getShell());
+ dialog.setDroolsRuntime(runtime);
+ if (dialog.open() == Window.OK) {
+ DroolsRuntime result = dialog.getResult();
+ if (result != null) {
+ // replace with the edited VM
+ int index = droolsRuntimes.indexOf(runtime);
+ droolsRuntimes.remove(index);
+ droolsRuntimes.add(index, result);
+ droolsRuntimesList.refresh();
+ droolsRuntimesList.setSelection(new StructuredSelection(result));
+ }
+ }
+ }
+
+ private void removeDroolsRuntimes() {
+ IStructuredSelection selection= (IStructuredSelection) droolsRuntimesList.getSelection();
+ DroolsRuntime[] runtimes = new DroolsRuntime[selection.size()];
+ Iterator<?> iter = selection.iterator();
+ int i = 0;
+ while (iter.hasNext()) {
+ runtimes[i] = (DroolsRuntime) iter.next();
+ i++;
+ }
+ removeDroolsRuntimes(runtimes);
+ }
+
+ public void removeDroolsRuntimes(DroolsRuntime[] runtimes) {
+ IStructuredSelection prev = (IStructuredSelection) getSelection();
+ for (int i = 0; i < runtimes.length; i++) {
+ droolsRuntimes.remove(runtimes[i]);
+ }
+ droolsRuntimesList.refresh();
+ IStructuredSelection curr = (IStructuredSelection) getSelection();
+ if (!curr.equals(prev)) {
+ runtimes = getDroolsRuntimes();
+ if (curr.size() == 0 && runtimes.length == 1) {
+ setSelection(new StructuredSelection(runtimes[0]));
+ } else {
+ fireSelectionChanged();
+ }
+ }
+ }
+
+ protected Shell getShell() {
+ return getControl().getShell();
+ }
+
+ public void setDefaultDroolsRuntime(DroolsRuntime runtime) {
+ if (runtime == null) {
+ setSelection(new StructuredSelection());
+ } else {
+ setSelection(new StructuredSelection(runtime));
+ }
+ }
+
+ public DroolsRuntime getDefaultDroolsRuntime() {
+ Object[] objects = droolsRuntimesList.getCheckedElements();
+ if (objects.length == 0) {
+ return null;
+ }
+ return (DroolsRuntime) objects[0];
+ }
+
+ public static class DroolsRuntime {
+ private String name;
+ private String path;
+ private boolean isDefault;
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getPath() {
+ return path;
+ }
+ public void setPath(String path) {
+ this.path = path;
+ }
+ public boolean isDefault() {
+ return isDefault;
+ }
+ public void setDefault(boolean isDefault) {
+ this.isDefault = isDefault;
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimesPreferencePage.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimesPreferencePage.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/DroolsRuntimesPreferencePage.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -0,0 +1,100 @@
+package org.drools.eclipse.preferences;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.preferences.DroolsRuntimesBlock.DroolsRuntime;
+import org.drools.eclipse.util.DroolsRuntimeManager;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+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.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class DroolsRuntimesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+ private DroolsRuntimesBlock droolsRuntimesBlock;
+
+ public DroolsRuntimesPreferencePage() {
+ super("Installed Drools Runtimes");
+ }
+
+ public void init(IWorkbench workbench) {
+ }
+
+ protected Control createContents(Composite ancestor) {
+ initializeDialogUnits(ancestor);
+ noDefaultAndApplyButton();
+ GridLayout layout= new GridLayout();
+ layout.numColumns= 1;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ ancestor.setLayout(layout);
+ Label l = new Label(ancestor, SWT.WRAP);
+ l.setFont(ancestor.getFont());
+ l.setText(
+ "Add, remove or edit Drools Runtime definitions. " +
+ "By default, the checked Drools Runtime is added to the build " +
+ "path of newly created Drools projects.");
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 1;
+ gd.widthHint = 300;
+ l.setLayoutData(gd);
+ l = new Label(ancestor, SWT.NONE);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.heightHint = 1;
+ l.setLayoutData(gd);
+ droolsRuntimesBlock = new DroolsRuntimesBlock();
+ droolsRuntimesBlock.createControl(ancestor);
+ DroolsRuntime[] runtimes = DroolsRuntimeManager.getDroolsRuntimes();
+ droolsRuntimesBlock.setDroolsRuntimes(runtimes);
+ for (DroolsRuntime runtime: runtimes) {
+ if (runtime.isDefault()) {
+ droolsRuntimesBlock.setDefaultDroolsRuntime(runtime);
+ break;
+ }
+ }
+ if (droolsRuntimesBlock.getDefaultDroolsRuntime() == null) {
+ setValid(false);
+ setErrorMessage("Select a default Drools Runtime");
+ }
+ Control control = droolsRuntimesBlock.getControl();
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.horizontalSpan = 1;
+ data.widthHint = 450;
+ control.setLayoutData(data);
+
+ droolsRuntimesBlock.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ DroolsRuntime runtime = droolsRuntimesBlock.getDefaultDroolsRuntime();
+ if (runtime == null) {
+ setValid(false);
+ setErrorMessage("Select a default Drools Runtime");
+ } else {
+ setValid(true);
+ setErrorMessage(null);
+ }
+ }
+ });
+ applyDialogFont(ancestor);
+ return ancestor;
+ }
+
+ public boolean performOk() {
+ if (DroolsRuntimeManager.getDefaultDroolsRuntime() != null) {
+ MessageDialog.openInformation(getShell(), "Warning",
+ "You need to restart Eclipse to update the Drools Runtime of existing projects.");
+ }
+ DroolsRuntimeManager.setDroolsRuntimes(droolsRuntimesBlock.getDroolsRuntimes());
+ return super.performOk();
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/IDroolsConstants.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/IDroolsConstants.java 2008-11-06 02:02:55 UTC (rev 23733)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/preferences/IDroolsConstants.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -10,5 +10,6 @@
String DSL_RULE_EDITOR_COMPLETION_FULL_SENTENCES = "Drools.DSLRuleEditorCompletionFullSentences";
String SKIN = "Drools.Flow.Skin";
String ALLOW_NODE_CUSTOMIZATION = "Drools.Flow.AllowNodeCustomization";
+ String DROOLS_RUNTIMES = "Drools.Runtimes";
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsClasspathContainer.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsClasspathContainer.java 2008-11-06 02:02:55 UTC (rev 23733)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsClasspathContainer.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -1,15 +1,16 @@
package org.drools.eclipse.util;
+import java.io.BufferedReader;
import java.io.File;
-import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.drools.eclipse.DroolsEclipsePlugin;
-import org.eclipse.core.runtime.FileLocator;
+import org.drools.eclipse.preferences.DroolsRuntimesBlock.DroolsRuntime;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
@@ -47,7 +48,7 @@
}
private IClasspathEntry[] createDroolsLibraryEntries(IJavaProject project) {
- List jarNames = getJarNames();
+ List jarNames = getJarNames(project);
List list = new ArrayList();
for (int i = 0; i < jarNames.size(); i++) {
Path path = new Path((String) jarNames.get(i));
@@ -55,46 +56,58 @@
path, path, null));
}
// also add jdt core jar from eclipse itself
- String pluginRootString = Platform.getInstallLocation().getURL().getPath() + "plugins/";
- File pluginRoot = new Path(pluginRootString).toFile();
- File[] files = pluginRoot.listFiles();
- for (int i = 0; i < files.length; i++) {
- if (files[i].getAbsolutePath().indexOf("org.eclipse.jdt.core_3.4") > -1) {
- Path path = new Path(files[i].getAbsolutePath());
- list.add(JavaCore.newLibraryEntry(path, path, null));
- break;
- }
- }
+// String pluginRootString = Platform.getInstallLocation().getURL().getPath() + "plugins/";
+// File pluginRoot = new Path(pluginRootString).toFile();
+// File[] files = pluginRoot.listFiles();
+// for (int i = 0; i < files.length; i++) {
+// if (files[i].getAbsolutePath().indexOf("org.eclipse.jdt.core_3.4") > -1) {
+// Path path = new Path(files[i].getAbsolutePath());
+// list.add(JavaCore.newLibraryEntry(path, path, null));
+// break;
+// }
+// }
return (IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]);
}
- private List getJarNames() {
- String s = getDroolsLocation();
+ private List getJarNames(IJavaProject project) {
+ String s = getDroolsLocation(project);
List list = new ArrayList();
- File file = (new Path(s)).toFile();
- addJarNames(file, list);
+ if (s != null) {
+ File file = (new Path(s)).toFile();
+ addJarNames(file, list);
+ }
return list;
}
private void addJarNames(File file, List list) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
- if (files[i].isDirectory() && files[i].getName().equals("lib")) {
- File[] jarFiles = files[i].listFiles();
- for (int j = 0; j < jarFiles.length; j++) {
- if (jarFiles[j].getPath().endsWith(".jar")) {
- list.add(jarFiles[j].getAbsolutePath());
- }
- }
+ if (files[i].getPath().endsWith(".jar")) {
+ list.add(files[i].getAbsolutePath());
}
}
}
- private String getDroolsLocation() {
+ private String getDroolsLocation(IJavaProject project) {
try {
- return FileLocator.toFileURL(Platform.getBundle("org.drools.eclipse")
- .getEntry("/")).getFile().toString();
- } catch (IOException e) {
+ IFile file = project.getProject().getFile(".drools.runtime");
+ if (file.exists()) {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()));
+ String location = reader.readLine();
+ if (location.startsWith("<runtime>") && location.endsWith("</runtime>")) {
+ location = location.substring(9, location.length() - 10);
+ DroolsRuntime runtime = DroolsRuntimeManager.getDroolsRuntime(location);
+ if (runtime != null) {
+ return runtime.getPath();
+ }
+ }
+ } else {
+ DroolsRuntime defaultRuntime = DroolsRuntimeManager.getDefaultDroolsRuntime();
+ if (defaultRuntime != null) {
+ return defaultRuntime.getPath();
+ }
+ }
+ } catch (Exception e) {
DroolsEclipsePlugin.log(e);
}
return null;
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsClasspathContainerInitializer.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsClasspathContainerInitializer.java 2008-11-06 02:02:55 UTC (rev 23733)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsClasspathContainerInitializer.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -15,4 +15,5 @@
JavaCore.setClasspathContainer(ipath, new IJavaProject[] { project },
new IClasspathContainer[] { container }, null);
}
+
}
Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsRuntimeManager.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsRuntimeManager.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/util/DroolsRuntimeManager.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -0,0 +1,160 @@
+package org.drools.eclipse.util;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.preferences.IDroolsConstants;
+import org.drools.eclipse.preferences.DroolsRuntimesBlock.DroolsRuntime;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+
+public class DroolsRuntimeManager {
+
+ public static void createDefaultRuntime(String location) {
+ List<String> jars = new ArrayList<String>();
+ // get all drools jars from drools eclipse plugin
+ String s = getDroolsLocation();
+ File file = (new Path(s)).toFile();
+ File[] files = file.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory() && files[i].getName().equals("lib")) {
+ File[] jarFiles = files[i].listFiles();
+ for (int j = 0; j < jarFiles.length; j++) {
+ if (jarFiles[j].getPath().endsWith(".jar")) {
+ jars.add(jarFiles[j].getAbsolutePath());
+ }
+ }
+ }
+ }
+ // get eclipse jdt jar
+ String pluginRootString = Platform.getInstallLocation().getURL().getPath() + "plugins/";
+ File pluginRoot = new Path(pluginRootString).toFile();
+ files = pluginRoot.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].getAbsolutePath().indexOf("org.eclipse.jdt.core_3.4") > -1) {
+ jars.add(files[i].getAbsolutePath());
+ break;
+ }
+ }
+ // copy jars to specified location
+ if (!location.endsWith(File.separator)) {
+ location = location + File.separator;
+ }
+ for (String jar: jars) {
+ try {
+ File jarFile = new File(jar);
+ FileChannel inChannel = new FileInputStream(jarFile).getChannel();
+ FileChannel outChannel = new FileOutputStream(new File(
+ location + jarFile.getName())).getChannel();
+ try {
+ inChannel.transferTo(0, inChannel.size(), outChannel);
+ }
+ catch (IOException e) {
+ throw e;
+ }
+ finally {
+ if (inChannel != null) inChannel.close();
+ if (outChannel != null) outChannel.close();
+ }
+ } catch (Throwable t) {
+ DroolsEclipsePlugin.log(t);
+ }
+ }
+ }
+
+ private static String getDroolsLocation() {
+ try {
+ return FileLocator.toFileURL(Platform.getBundle("org.drools.eclipse")
+ .getEntry("/")).getFile().toString();
+ } catch (IOException e) {
+ DroolsEclipsePlugin.log(e);
+ }
+ return null;
+ }
+
+ private static String generateString(DroolsRuntime[] droolsRuntimes) {
+ String result = "";
+ for (DroolsRuntime runtime: droolsRuntimes) {
+ result += runtime.getName() + "#" + runtime.getPath() + "#" + runtime.isDefault() + "###";
+ }
+ return result;
+ }
+
+ private static DroolsRuntime[] generateRuntimes(String s) {
+ List<DroolsRuntime> result = new ArrayList<DroolsRuntime>();
+ if (s != null && !"".equals(s)) {
+ String[] runtimeStrings = s.split("###");
+ for (String runtimeString: runtimeStrings) {
+ String[] properties = runtimeString.split("#");
+ DroolsRuntime runtime = new DroolsRuntime();
+ runtime.setName(properties[0]);
+ runtime.setPath(properties[1]);
+ runtime.setDefault("true".equals(properties[2]));
+ result.add(runtime);
+ }
+ }
+ return result.toArray(new DroolsRuntime[result.size()]);
+ }
+
+ public static DroolsRuntime[] getDroolsRuntimes() {
+ String runtimesString = DroolsEclipsePlugin.getDefault().getPreferenceStore()
+ .getString(IDroolsConstants.DROOLS_RUNTIMES);
+ if (runtimesString != null) {
+ return generateRuntimes(runtimesString);
+ }
+ return new DroolsRuntime[0];
+ }
+
+ public static void setDroolsRuntimes(DroolsRuntime[] runtimes) {
+ DroolsEclipsePlugin.getDefault().getPreferenceStore().setValue(IDroolsConstants.DROOLS_RUNTIMES,
+ DroolsRuntimeManager.generateString(runtimes));
+ }
+
+ public static DroolsRuntime getDroolsRuntime(String name) {
+ DroolsRuntime[] runtimes = getDroolsRuntimes();
+ for (DroolsRuntime runtime: runtimes) {
+ if (runtime.getName().equals(name)) {
+ return runtime;
+ }
+ }
+ return null;
+ }
+
+ public static DroolsRuntime getDefaultDroolsRuntime() {
+ DroolsRuntime[] runtimes = getDroolsRuntimes();
+ for (DroolsRuntime runtime: runtimes) {
+ if (runtime.isDefault()) {
+ return runtime;
+ }
+ }
+ return null;
+ }
+
+ public static String getDroolsRuntime(IProject project) {
+ try {
+ IFile file = project.getFile(".drools.runtime");
+ if (file.exists()) {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()));
+ String location = reader.readLine();
+ if (location.startsWith("<runtime>") && location.endsWith("</runtime>")) {
+ return location.substring(9, location.length() - 10);
+ }
+ }
+ } catch (Exception e) {
+ DroolsEclipsePlugin.log(e);
+ }
+ return null;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/wizard/project/NewDroolsProjectRuntimeWizardPage.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/wizard/project/NewDroolsProjectRuntimeWizardPage.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/wizard/project/NewDroolsProjectRuntimeWizardPage.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -0,0 +1,145 @@
+package org.drools.eclipse.wizard.project;
+
+import java.util.HashMap;
+
+import org.drools.eclipse.preferences.DroolsProjectPreferencePage;
+import org.drools.eclipse.preferences.DroolsRuntimesBlock.DroolsRuntime;
+import org.drools.eclipse.util.DroolsRuntimeManager;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+
+public class NewDroolsProjectRuntimeWizardPage extends WizardPage {
+
+ private boolean isDefaultRuntime = true;
+ private String selectedRuntime;
+ private Button projectSpecificRuntime;
+ private Combo droolsRuntimeCombo;
+
+ public NewDroolsProjectRuntimeWizardPage() {
+ super("extendedNewProjectRuntimePage");
+ setTitle("Drools Runtime");
+ setDescription("Select a Drools Runtime");
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ composite.setLayout(gridLayout);
+
+ DroolsRuntime defaultRuntime = DroolsRuntimeManager.getDefaultDroolsRuntime();
+ projectSpecificRuntime = createCheckBox(composite,
+ "Use default Drools Runtime (currently "
+ + (defaultRuntime == null ? "undefined)" : defaultRuntime.getName() + ")"));
+ projectSpecificRuntime.setSelection(true);
+ projectSpecificRuntime.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+ public void widgetSelected(SelectionEvent e) {
+ isDefaultRuntime = ((Button) e.widget).getSelection();
+ droolsRuntimeCombo.setEnabled(!isDefaultRuntime);
+ }
+ });
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = 2;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ projectSpecificRuntime.setLayoutData(gridData);
+
+ Label nameLabel = new Label(composite, SWT.NONE);
+ nameLabel.setText("Drools Runtime: ");
+ droolsRuntimeCombo = new Combo(composite, SWT.LEFT);
+ droolsRuntimeCombo.setEnabled(false);
+ droolsRuntimeCombo.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ selectedRuntime = droolsRuntimeCombo.getText();
+ }
+ public void widgetSelected(SelectionEvent e) {
+ selectedRuntime = droolsRuntimeCombo.getText();
+ }
+ });
+ DroolsRuntime[] runtimes = DroolsRuntimeManager.getDroolsRuntimes();
+ if (runtimes.length == 0) {
+ setErrorMessage("No Drools Runtimes have been defined, configure workspace settings first");
+ } else {
+ setErrorMessage(null);
+ for (int i = 0; i < runtimes.length; i++) {
+ droolsRuntimeCombo.add(runtimes[i].getName());
+ }
+ droolsRuntimeCombo.select(0);
+ selectedRuntime = droolsRuntimeCombo.getText();
+ }
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ droolsRuntimeCombo.setLayoutData(gridData);
+ Link changeWorkspaceSettingsLink = createLink(composite, "Configure Workspace Settings...");
+ changeWorkspaceSettingsLink.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
+
+ setMessage(null);
+ setPageComplete(runtimes.length > 0);
+ setControl(composite);
+ }
+
+ private Button createCheckBox(Composite group, String label) {
+ Button button = new Button(group, SWT.CHECK | SWT.LEFT);
+ button.setText(label);
+ GridData data = new GridData();
+ button.setLayoutData(data);
+ return button;
+ }
+
+ private Link createLink(Composite composite, String text) {
+ Link link= new Link(composite, SWT.NONE);
+ link.setFont(composite.getFont());
+ link.setText("<A>" + text + "</A>"); //$NON-NLS-1$//$NON-NLS-2$
+ link.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ openLink();
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ openLink();
+ }
+ });
+ return link;
+ }
+
+ private void openLink() {
+ PreferencesUtil.createPreferenceDialogOn(getShell(),
+ DroolsProjectPreferencePage.PREF_ID,
+ new String[] { DroolsProjectPreferencePage.PROP_ID }, new HashMap()).open();
+ droolsRuntimeCombo.removeAll();
+ DroolsRuntime[] runtimes = DroolsRuntimeManager.getDroolsRuntimes();
+ if (runtimes.length == 0) {
+ setPageComplete(false);
+ setErrorMessage("No Drools Runtimes have been defined, please do this first");
+ } else {
+ setPageComplete(true);
+ setErrorMessage(null);
+ for (int i = 0; i < runtimes.length; i++) {
+ droolsRuntimeCombo.add(runtimes[i].getName());
+ }
+ droolsRuntimeCombo.select(0);
+ selectedRuntime = droolsRuntimeCombo.getText();
+ }
+ }
+
+ public DroolsRuntime getDroolsRuntime() {
+ if (isDefaultRuntime) {
+ return null;
+ }
+ return DroolsRuntimeManager.getDroolsRuntime(selectedRuntime);
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/wizard/project/NewDroolsProjectWizard.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/wizard/project/NewDroolsProjectWizard.java 2008-11-06 02:02:55 UTC (rev 23733)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/wizard/project/NewDroolsProjectWizard.java 2008-11-06 02:16:43 UTC (rev 23734)
@@ -1,5 +1,6 @@
package org.drools.eclipse.wizard.project;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
@@ -9,6 +10,7 @@
import org.drools.eclipse.DroolsEclipsePlugin;
import org.drools.eclipse.builder.DroolsBuilder;
+import org.drools.eclipse.preferences.DroolsRuntimesBlock.DroolsRuntime;
import org.drools.eclipse.util.DroolsClasspathContainer;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IContainer;
@@ -54,6 +56,7 @@
private IProject newProject;
private WizardNewProjectCreationPage mainPage;
private NewDroolsProjectWizardPage extraPage;
+ private NewDroolsProjectRuntimeWizardPage runtimePage;
public void addPages() {
super.addPages();
@@ -63,6 +66,8 @@
this.addPage(mainPage);
extraPage = new NewDroolsProjectWizardPage();
addPage(extraPage);
+ runtimePage = new NewDroolsProjectRuntimeWizardPage();
+ addPage(runtimePage);
setNeedsProgressMonitor(true);
}
@@ -82,6 +87,7 @@
throws CoreException {
try {
IJavaProject project = JavaCore.create(newProject);
+ createDroolsRuntime(project, monitor);
createOutputLocation(project, monitor);
addJavaBuilder(project, monitor);
setClasspath(project, monitor);
@@ -177,6 +183,15 @@
}
}
+ private void createDroolsRuntime(IJavaProject project, IProgressMonitor monitor) throws CoreException {
+ DroolsRuntime runtime = runtimePage.getDroolsRuntime();
+ if (runtime != null) {
+ IFile file = project.getProject().getFile(".drools.runtime");
+ file.create(new ByteArrayInputStream(
+ ("<runtime>" + runtime.getName() + "</runtime>").getBytes()), true, monitor);
+ }
+ }
+
private void createOutputLocation(IJavaProject project, IProgressMonitor monitor)
throws JavaModelException, CoreException {
IFolder folder = project.getProject().getFolder("bin");
More information about the jboss-svn-commits
mailing list