Author: adietish
Date: 2011-11-17 07:05:44 -0500 (Thu, 17 Nov 2011)
New Revision: 36402
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java
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] implementing "embed cartridge"
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java 2011-11-17
12:05:12 UTC (rev 36401)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java 2011-11-17
12:05:44 UTC (rev 36402)
@@ -2,6 +2,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -15,7 +16,7 @@
// The shared instance
private static OpenShiftUIActivator plugin;
-
+
/**
* The constructor
*/
@@ -24,7 +25,10 @@
/*
* (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
*/
public void start(BundleContext context) throws Exception {
super.start(context);
@@ -33,7 +37,10 @@
/*
* (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
@@ -42,13 +49,13 @@
/**
* Returns the shared instance
- *
+ *
* @return the shared instance
*/
public static OpenShiftUIActivator getDefault() {
return plugin;
}
-
+
public static void log(IStatus status) {
plugin.getLog().log(status);
}
@@ -58,8 +65,10 @@
}
public static IStatus createErrorStatus(String message, Throwable throwable) {
- return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- message, throwable);
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, throwable);
}
-
+
+ public static IStatus createErrorStatus(String message, Throwable throwable, Object...
arguments) {
+ return createErrorStatus(NLS.bind(message, arguments), throwable);
+ }
}
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-17
12:05:44 UTC (rev 36402)
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.MessageDialog;
+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.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ICheckStateListener;
+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.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Table;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+/**
+ * @author André Dietisheim
+ */
+public class EmbedCartridgeWizardPage extends AbstractOpenShiftWizardPage {
+
+ private EmbedCartridgeWizardPageModel model;
+ private CheckboxTableViewer viewer;
+
+ public EmbedCartridgeWizardPage(NewApplicationWizardModel wizardModel, IWizard wizard)
{
+ super("Embed Cartridges", "Please select the cartridges to embed into
your application",
+ "EmbedCartridgePage", wizard);
+ this.model = new EmbedCartridgeWizardPageModel(wizardModel);
+ }
+
+ @Override
+ protected void doCreateControls(Composite parent, DataBindingContext dbc) {
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(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);
+ viewer.addCheckStateListener(onEmbeddableCartridgeChecked());
+
+ }
+
+ protected CheckboxTableViewer 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);
+ CheckboxTableViewer viewer = new CheckboxTableViewer(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));
+ }
+
+ private ICheckStateListener onEmbeddableCartridgeChecked() {
+ return new ICheckStateListener() {
+
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
+ if (event.getChecked()) {
+ if (IEmbeddableCartridge.PHPMYADMIN_34.equals(cartridge)) {
+ addPhpMyACartridge(cartridge);
+ }
+ else if (IEmbeddableCartridge.JENKINS_14.equals(cartridge)) {
+ addJenkinsCartridge(cartridge);
+ }
+ } else {
+ model.getSelectedEmbeddableCartridges().remove(cartridge);
+ }
+ }
+ };
+ }
+
+ private void addJenkinsCartridge(IEmbeddableCartridge cartridge) {
+ model.getSelectedEmbeddableCartridges().add(cartridge);
+ }
+
+ private void addPhpMyACartridge(IEmbeddableCartridge cartridge) {
+ MessageDialog.openQuestion(getShell(), "Enable MySQL cartridge", "To
embed PhpMyAdmin, you'd also have to embed MySql. ");
+ model.getSelectedEmbeddableCartridges().add(cartridge);
+ }
+
+ @Override
+ protected void onPageActivated(DataBindingContext dbc) {
+ try {
+ WizardUtils.runInWizard(new Job("Loading embeddable cartridges...") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ setCartridgesViewerInput(model.loadEmbeddableCartridges());
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ clearCartridgesViewer();
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could not load embeddable cartridges", e);
+ }
+ }
+
+ }, getContainer(), getDataBindingContext());
+ } catch (Exception e) {
+ // ignore
+ }
+
+ }
+
+ private void clearCartridgesViewer() {
+ setCartridgesViewerInput(new ArrayList<IEmbeddableCartridge>());
+ }
+
+ private void setCartridgesViewerInput(final Collection<IEmbeddableCartridge>
cartridges) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ viewer.setInput(cartridges);
+ }
+ });
+ }
+}
\ No newline at end of file
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-17
12:05:44 UTC (rev 36402)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+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;
+
+/**
+ * @author André Dietisheim
+ */
+public class EmbedCartridgeWizardPageModel extends ObservableUIPojo {
+
+ 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 NewApplicationWizardModel wizardModel;
+
+ private List<IEmbeddableCartridge> embeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
+ private List<IEmbeddableCartridge> selectedEmbeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
+
+ public EmbedCartridgeWizardPageModel(NewApplicationWizardModel wizardModel) {
+ this.wizardModel = wizardModel;
+ }
+
+ public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws
OpenShiftException {
+ List<IEmbeddableCartridge> cartridges =
wizardModel.getUser().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 List<IEmbeddableCartridge> getSelectedEmbeddableCartridges() {
+ return selectedEmbeddableCartridges;
+ }
+
+ public boolean hasApplication(ICartridge cartridge) {
+ try {
+ return wizardModel.getUser().hasApplication(cartridge);
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log(
+ OpenShiftUIActivator.createErrorStatus("Could not get application by
cartridge", e));
+ return false;
+ }
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java 2011-11-17
12:05:12 UTC (rev 36401)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java 2011-11-17
12:05:44 UTC (rev 36402)
@@ -30,10 +30,10 @@
*/
public class NewApplicationDialog extends Wizard {
- private NewApplicationWizardPageModel newApplicationModel;
+ private NewApplicationWizardModel newApplicationWizardModel;
public NewApplicationDialog(IUser user) {
- this.newApplicationModel = new NewApplicationWizardPageModel(user);
+ this.newApplicationWizardModel = new NewApplicationWizardModel(user);
setNeedsProgressMonitor(true);
}
@@ -46,12 +46,12 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- newApplicationModel.createApplication();
+ newApplicationWizardModel.createApplication();
queue.offer(true);
} catch (OpenShiftException e) {
queue.offer(false);
return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- NLS.bind("Could not create application \"{0}\"",
newApplicationModel.getName()), e);
+ NLS.bind("Could not create application \"{0}\"",
newApplicationWizardModel.getName()), e);
}
return Status.OK_STATUS;
}
@@ -64,10 +64,11 @@
@Override
public void addPages() {
- addPage(new NewApplicationWizardPage(newApplicationModel, this));
+ addPage(new NewApplicationWizardPage(newApplicationWizardModel, this));
+ addPage(new EmbedCartridgeWizardPage(newApplicationWizardModel, this));
}
public IApplication getApplication() {
- return newApplicationModel.getApplication();
+ return newApplicationWizardModel.getApplication();
}
}
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java 2011-11-17
12:05:44 UTC (rev 36402)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.openshift.express.internal.ui.wizard;
+
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.client.IApplication;
+import org.jboss.tools.openshift.express.client.ICartridge;
+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;
+
+/**
+ * @author André Dietisheim
+ */
+public class NewApplicationWizardModel extends ObservableUIPojo {
+
+ private IUser user;
+
+ private String name;
+ private ICartridge cartridge;
+
+ private IApplication application;
+
+ public NewApplicationWizardModel(IUser user) {
+ this.user = user;
+ }
+
+ public IUser getUser() {
+ return user;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String setName(String name) {
+ return this.name = name;
+ }
+
+ public ICartridge getCartridge() {
+ return cartridge;
+ }
+
+ public void setCartridge(ICartridge cartridge) {
+ this.cartridge = cartridge;
+ }
+
+ public void setApplication(IApplication application) {
+ this.application = application;
+ }
+
+ public void createApplication() throws OpenShiftException {
+ IApplication application = user.createApplication(name, cartridge);
+ setApplication(application);
+ }
+
+ public IApplication getApplication() {
+ return application;
+ }
+
+ public boolean hasApplication(String name) {
+ try {
+ return user.getApplicationByName(name) != null;
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log(
+ OpenShiftUIActivator.createErrorStatus("Could not get application by
name", e));
+ return false;
+ }
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-17
12:05:12 UTC (rev 36401)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-11-17
12:05:44 UTC (rev 36402)
@@ -10,9 +10,6 @@
******************************************************************************/
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;
@@ -27,32 +24,19 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.dialogs.PageChangingEvent;
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.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.ICheckStateListener;
-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;
@@ -62,12 +46,13 @@
public class NewApplicationWizardPage extends AbstractOpenShiftWizardPage {
private NewApplicationWizardPageModel model;
- private CheckboxTableViewer viewer;
+ private NewApplicationWizardModel wizardModel;
- public NewApplicationWizardPage(NewApplicationWizardPageModel model, IWizard wizard) {
+ public NewApplicationWizardPage(NewApplicationWizardModel wizardModel, IWizard wizard)
{
super("Create new OpenShift Express application", "Create new OpenShift
Express application",
"Create new OpenShift Express application", wizard);
- this.model = model;
+ this.wizardModel = wizardModel;
+ this.model = new NewApplicationWizardPageModel(wizardModel);
}
@Override
@@ -144,70 +129,8 @@
}
}));
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);
- viewer.addCheckStateListener(onEmbeddableCartridgeSelected());
- }
-
- private ICheckStateListener onEmbeddableCartridgeSelected() {
- return new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent event) {
- IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
- if (event.getChecked()) {
- model.getSeleEmbeddableCartridges().add(cartridge);
- } else {
- model.getSeleEmbeddableCartridges().remove(cartridge);
- }
- }
- };
- }
-
- protected CheckboxTableViewer 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);
- CheckboxTableViewer viewer = new CheckboxTableViewer(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 {
@@ -226,43 +149,31 @@
} catch (Exception e) {
// ignore
}
+ }
+
+ @Override
+ protected void onPageWillGetDeactivated(Direction progress, final PageChangingEvent
event, DataBindingContext dbc) {
+ final String name = wizardModel.getName();
try {
- WizardUtils.runInWizard(new Job("Loading embeddable cartridges...") {
+ WizardUtils.runInWizard(new Job(NLS.bind("Creating application
\"{0}\"...", name)) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- setCartridgesViewerInput(model.loadEmbeddableCartridges());
- return Status.OK_STATUS;
- } catch (Exception e) {
- clearCartridgesViewer();
- return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "Could not load embeddable cartridges", e);
+ wizardModel.createApplication();
+ } catch (OpenShiftException e) {
+ event.doit = false;
+ return OpenShiftUIActivator.createErrorStatus("Could not create application
\"{0}\"", e, name);
}
+ return Status.OK_STATUS;
}
-
- }, getContainer(), getDataBindingContext());
+ }, getContainer());
} catch (Exception e) {
// ignore
}
-
}
- private void clearCartridgesViewer() {
- setCartridgesViewerInput(new ArrayList<IEmbeddableCartridge>());
- }
-
- private void setCartridgesViewerInput(final Collection<IEmbeddableCartridge>
cartridges) {
- getShell().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- viewer.setInput(cartridges);
- }
- });
- }
-
private class ApplicationNameValidator implements IValidator {
@Override
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-17
12:05:12 UTC (rev 36401)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java 2011-11-17
12:05:44 UTC (rev 36402)
@@ -15,10 +15,7 @@
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
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;
@@ -30,22 +27,16 @@
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;
- private String name;
- private IApplication application;
+ private NewApplicationWizardModel wizardModel;
private List<ICartridge> cartridges = new ArrayList<ICartridge>();
private ICartridge selectedCartridge;
private StringPreferenceValue selectedCartridgePreference;
- private List<IEmbeddableCartridge> embeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
- private List<IEmbeddableCartridge> selectedEmbeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
-
- public NewApplicationWizardPageModel(IUser user) {
- this.user = user;
+ public NewApplicationWizardPageModel(NewApplicationWizardModel wizardModel) {
+ this.wizardModel = wizardModel;
this.selectedCartridgePreference = new StringPreferenceValue(
"org.jboss.tools.openshift.express.internal.ui.wizard.NewApplicationWizard.selectedCartridge",
OpenShiftUIActivator.PLUGIN_ID);
@@ -69,15 +60,16 @@
}
public String getName() {
- return name;
+ return wizardModel.getName();
}
public void setName(String name) {
- firePropertyChange(PROPERTY_NAME, this.name, this.name = name);
+ wizardModel.setName(name);
+ firePropertyChange(PROPERTY_NAME, wizardModel.getName(), wizardModel.setName(name));
}
public void loadCartridges() throws OpenShiftException {
- setCartridges(user.getCartridges());
+ setCartridges(wizardModel.getUser().getCartridges());
}
public void setCartridges(List<ICartridge> cartridges) {
@@ -94,6 +86,7 @@
}
public void setSelectedCartridge(ICartridge cartridge) {
+ wizardModel.setCartridge(cartridge);
if (cartridge != null) {
selectedCartridgePreference.store(cartridge.getName());
}
@@ -111,41 +104,9 @@
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 List<IEmbeddableCartridge> getSeleEmbeddableCartridges() {
- return selectedEmbeddableCartridges;
- }
-
- public void createApplication() throws OpenShiftException {
- IApplication application = user.createApplication(name, selectedCartridge);
- setApplication(application);
- }
-
- public void setApplication(IApplication application) {
- firePropertyChange(PROPERTY_APPLICATION, this.application, this.application =
application);
- }
-
- public IApplication getApplication() {
- return application;
- }
-
public boolean hasApplication(String name) {
try {
- return user.getApplicationByName(name) != null;
+ return wizardModel.getUser().getApplicationByName(name) != null;
} catch (OpenShiftException e) {
OpenShiftUIActivator.log(
OpenShiftUIActivator.createErrorStatus("Could not get application by
name", e));