Author: adietish
Date: 2011-11-16 11:00:56 -0500 (Wed, 16 Nov 2011)
New Revision: 36372
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java
Log:
[JBIDE-9927] added checkbox table with embeddable cartridges
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-11-16
16:00:22 UTC (rev 36371)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-11-16
16:00:56 UTC (rev 36372)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
+import java.util.ArrayList;
+import java.util.Collection;
+
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateListStrategy;
@@ -26,16 +29,27 @@
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.openshift.express.client.Cartridge;
import org.jboss.tools.openshift.express.client.ICartridge;
+import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
import org.jboss.tools.openshift.express.client.OpenShiftException;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
@@ -45,6 +59,7 @@
public class NewApplicationWizardPage extends AbstractOpenShiftWizardPage {
private NewApplicationWizardPageModel model;
+ private TableViewer viewer;
public NewApplicationWizardPage(NewApplicationWizardPageModel model, IWizard wizard) {
super("Create new OpenShift Express application", "Create new OpenShift
Express application",
@@ -93,7 +108,7 @@
WidgetProperties.selection().observe(cartridgesCombo)
,
BeanProperties.value(NewApplicationWizardPageModel.PROPERTY_SELECTED_CARTRIDGE).observe(model)
, new UpdateValueStrategy().setConverter(new Converter(String.class,
ICartridge.class) {
-
+
@Override
public Object convert(Object fromObject) {
if (fromObject instanceof String
@@ -116,18 +131,64 @@
}
})
, new UpdateValueStrategy().setConverter(new Converter(ICartridge.class,
String.class) {
-
- @Override
- public Object convert(Object fromObject) {
- if (fromObject instanceof ICartridge) {
- return ((ICartridge) fromObject).getName();
- }
- return null;
- }
- }));
+
+ @Override
+ public Object convert(Object fromObject) {
+ if (fromObject instanceof ICartridge) {
+ return ((ICartridge) fromObject).getName();
+ }
+ return null;
+ }
+ }));
ControlDecorationSupport.create(comboSelectionBinding, SWT.LEFT | SWT.TOP);
+
+ createEmbedGroup(parent);
}
+ private void createEmbedGroup(Composite parent) {
+ Group embedGroup = new Group(parent, SWT.NONE);
+ embedGroup.setText("Embeddable Cartridges");
+ GridDataFactory.fillDefaults()
+ .hint(300, 150).align(SWT.FILL, SWT.FILL).span(2, 1).grab(true, true)
+ .applyTo(embedGroup);
+ FillLayout fillLayout = new FillLayout();
+ fillLayout.marginHeight = 6;
+ fillLayout.marginWidth = 6;
+ embedGroup.setLayout(fillLayout);
+
+ Composite tableContainer = new Composite(embedGroup, SWT.NONE);
+ this.viewer = createTable(tableContainer);
+ }
+
+ protected TableViewer createTable(Composite tableContainer) {
+ Table table =
+ new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL |
SWT.H_SCROLL | SWT.CHECK);
+ table.setLinesVisible(true);
+ TableColumnLayout tableLayout = new TableColumnLayout();
+ tableContainer.setLayout(tableLayout);
+ TableViewer viewer = new TableViewer(table);
+ viewer.setContentProvider(new ArrayContentProvider());
+
+ createTableColumn("Embeddable Cartridge", 1, new CellLabelProvider() {
+
+ @Override
+ public void update(ViewerCell cell) {
+ IEmbeddableCartridge cartridge = (IEmbeddableCartridge) cell.getElement();
+ cell.setText(cartridge.getName());
+ }
+ }, viewer, tableLayout);
+ return viewer;
+ }
+
+ private void createTableColumn(String name, int weight, CellLabelProvider
cellLabelProvider, TableViewer viewer,
+ TableColumnLayout layout) {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT);
+ column.getColumn().setText(name);
+ column.setLabelProvider(cellLabelProvider);
+
+ layout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
+ }
+
@Override
protected void onPageActivated(DataBindingContext dbc) {
try {
@@ -146,8 +207,43 @@
} catch (Exception e) {
// ignore
}
+
+ try {
+ WizardUtils.runInWizard(new Job("Loading embeddable cartridges...") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ setViewerInput(model.loadEmbeddableCartridges());
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ clearViewer();
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could not load embeddable cartridges", e);
+ }
+ }
+
+ }, getContainer(), getDataBindingContext());
+ } catch (Exception e) {
+ // ignore
+ }
+
}
+ private void clearViewer() {
+ setViewerInput(new ArrayList<IEmbeddableCartridge>());
+ }
+
+ private void setViewerInput(final Collection<IEmbeddableCartridge> cartridges) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ viewer.setInput(cartridges);
+ }
+ });
+ }
+
private class ApplicationNameValidator implements IValidator {
@Override
@@ -162,4 +258,5 @@
return ValidationStatus.ok();
}
}
+
}
\ No newline at end of file
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java 2011-11-16
16:00:22 UTC (rev 36371)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java 2011-11-16
16:00:56 UTC (rev 36372)
@@ -17,6 +17,7 @@
import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
import org.jboss.tools.openshift.express.client.IApplication;
import org.jboss.tools.openshift.express.client.ICartridge;
+import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
import org.jboss.tools.openshift.express.client.IUser;
import org.jboss.tools.openshift.express.client.OpenShiftException;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
@@ -29,6 +30,7 @@
public static final String PROPERTY_APPLICATION = "application";
public static final String PROPERTY_NAME = "name";
public static final String PROPERTY_CARTRIDGES = "cartridges";
+ public static final String PROPERTY_EMBEDDABLE_CARTRIDGES =
"embeddableCartridges";
public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
private IUser user;
@@ -39,6 +41,8 @@
private ICartridge selectedCartridge;
private StringPreferenceValue selectedCartridgePreference;
+ private List<IEmbeddableCartridge> embeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
+
public NewApplicationWizardPageModel(IUser user) {
this.user = user;
this.selectedCartridgePreference = new StringPreferenceValue(
@@ -106,6 +110,21 @@
return matchingCartridge;
}
+ public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws
OpenShiftException {
+ List<IEmbeddableCartridge> cartridges = user.getEmbeddableCartridges();
+ setEmbeddableCartridges(cartridges);
+ return cartridges;
+ }
+
+ public void setEmbeddableCartridges(List<IEmbeddableCartridge> cartridges) {
+ firePropertyChange(
+ PROPERTY_EMBEDDABLE_CARTRIDGES, this.embeddableCartridges, this.embeddableCartridges
= cartridges);
+ }
+
+ public List<IEmbeddableCartridge> getEmbeddableCartridges() {
+ return embeddableCartridges;
+ }
+
public void createApplication() throws OpenShiftException {
IApplication application = user.createApplication(name, selectedCartridge);
setApplication(application);
@@ -114,7 +133,7 @@
public void setApplication(IApplication application) {
firePropertyChange(PROPERTY_APPLICATION, this.application, this.application =
application);
}
-
+
public IApplication getApplication() {
return application;
}