Author: adietish
Date: 2011-11-21 07:57:31 -0500 (Mon, 21 Nov 2011)
New Revision: 36481
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/AdapterWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java
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/NewApplicationWizard.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java
Log:
[JBIDE-9927] implementing create application and embed cartridges usecase
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-21
12:44:41 UTC (rev 36480)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java 2011-11-21
12:57:31 UTC (rev 36481)
@@ -61,9 +61,13 @@
}
public static void log(Throwable e) {
- log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
+ log(e.getMessage(), e);
}
+ public static void log(String message, Throwable e) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e));
+ }
+
public static IStatus createErrorStatus(String message, Throwable throwable) {
return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, throwable);
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java 2011-11-21
12:44:41 UTC (rev 36480)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java 2011-11-21
12:57:31 UTC (rev 36481)
@@ -12,18 +12,14 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import java.util.ArrayList;
-import java.util.List;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
-import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.MultiValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -31,41 +27,25 @@
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IRuntimeType;
-import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
import org.eclipse.wst.server.core.IServerType;
import org.eclipse.wst.server.core.ServerCore;
-import org.eclipse.wst.server.core.TaskModel;
-import org.eclipse.wst.server.ui.internal.Messages;
-import org.eclipse.wst.server.ui.internal.ServerUIPlugin;
-import org.eclipse.wst.server.ui.internal.wizard.TaskWizard;
-import org.eclipse.wst.server.ui.internal.wizard.WizardTaskUtil;
-import org.eclipse.wst.server.ui.wizard.WizardFragment;
-import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.tools.common.ui.databinding.DataBindingUtils;
import org.jboss.tools.common.ui.databinding.InvertingBooleanConverter;
import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
-import org.jboss.tools.openshift.express.client.ICartridge;
import org.jboss.tools.openshift.express.client.OpenShiftException;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java 2011-11-21
12:44:41 UTC (rev 36480)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java 2011-11-21
12:57:31 UTC (rev 36481)
@@ -10,19 +10,9 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import org.eclipse.core.databinding.observable.Diffs;
-import org.eclipse.core.databinding.observable.list.ListDiff;
-import org.eclipse.core.databinding.observable.list.ListDiffEntry;
-import org.eclipse.core.runtime.Assert;
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.IEmbeddableCartridge;
import org.jboss.tools.openshift.express.client.IUser;
import org.jboss.tools.openshift.express.client.OpenShiftException;
@@ -37,7 +27,6 @@
private IApplication application;
private String name;
private ICartridge cartridge;
- private List<IEmbeddableCartridge> selectedCartridges;
public ApplicationWizardModel(IUser user) {
this(null, user);
@@ -80,61 +69,4 @@
public IApplication createApplication(String name, ICartridge cartridge) throws
OpenShiftException {
return getUser().createApplication(name, cartridge);
}
-
- public void setSelectedCartridges(List<IEmbeddableCartridge> selectedCartridges)
{
- this.selectedCartridges = selectedCartridges;
- }
-
- public void embedCartridges() throws OpenShiftException {
- Assert.isNotNull(selectedCartridges);
- List<IEmbeddableCartridge> addedCartridges = new
ArrayList<IEmbeddableCartridge>();
- List<IEmbeddableCartridge> removedCartridges = new
ArrayList<IEmbeddableCartridge>();
- computeAdditionsAndRemovals(addedCartridges, removedCartridges, selectedCartridges);
- addEmbeddedCartridges(addedCartridges);
- removeEmbeddedCartridges(removedCartridges);
- }
-
- private void removeEmbeddedCartridges(List<IEmbeddableCartridge>
removedCartridges) throws OpenShiftException {
- if (removedCartridges.isEmpty()) {
- return;
- }
- Collections.sort(removedCartridges, new CartridgeComparator());
- application.removeEmbbedCartridges(removedCartridges);
- }
-
- private void addEmbeddedCartridges(List<IEmbeddableCartridge> addedCartridges)
throws OpenShiftException {
- if (addedCartridges.isEmpty()) {
- return;
- }
- Collections.sort(addedCartridges, new CartridgeComparator());
- application.addEmbbedCartridges(addedCartridges);
- }
-
- private void computeAdditionsAndRemovals(List<IEmbeddableCartridge>
addedCartridges,
- List<IEmbeddableCartridge> removedCartridges, List<IEmbeddableCartridge>
selectedCartridges)
- throws OpenShiftException {
- ListDiff listDiff = Diffs.computeListDiff(getApplication().getEmbeddedCartridges(),
selectedCartridges);
- for (ListDiffEntry entry : listDiff.getDifferences()) {
- if (entry.isAddition()) {
- addedCartridges.add((IEmbeddableCartridge) entry.getElement());
- } else {
- removedCartridges.add((IEmbeddableCartridge) entry.getElement());
- }
- }
- }
-
- private static class CartridgeComparator implements
Comparator<IEmbeddableCartridge> {
-
- @Override
- public int compare(IEmbeddableCartridge thisCartridge, IEmbeddableCartridge
thatCartridge) {
- // mysql has to be added/removed before phpmyadmin
- if (thisCartridge.equals(IEmbeddableCartridge.MYSQL_51)) {
- return -1;
- } else if (thatCartridge.equals(IEmbeddableCartridge.MYSQL_51)) {
- return 1;
- }
- return 0;
- }
- }
-
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java 2011-11-21
12:44:41 UTC (rev 36480)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java 2011-11-21
12:57:31 UTC (rev 36481)
@@ -10,20 +10,9 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-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.wizard.Wizard;
-import org.eclipse.osgi.util.NLS;
-import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.openshift.express.client.IApplication;
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
@@ -31,6 +20,7 @@
public class EmbedCartridgeWizard extends Wizard {
private ApplicationWizardModel wizardModel;
+ private EmbedCartridgeWizardPage embedCartridgeWizardPage;
public EmbedCartridgeWizard(IApplication application, IUser user) {
this.wizardModel = new ApplicationWizardModel(application, user);
@@ -39,35 +29,12 @@
@Override
public boolean performFinish() {
- final ArrayBlockingQueue<Boolean> queue = new
ArrayBlockingQueue<Boolean>(1);
- try {
- WizardUtils.runInWizard(
- new Job(NLS.bind("Adding/Removing embedded cartridges for application
{0}...",
- wizardModel.getApplication().getName())) {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- wizardModel.embedCartridges();
- queue.offer(true);
- } catch (OpenShiftException e) {
- queue.offer(false);
- return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- NLS.bind("Could not embed cartridges to application {0}",
- wizardModel.getApplication().getName()), e);
- }
- return Status.OK_STATUS;
- }
- }, getContainer());
- return queue.poll(10, TimeUnit.SECONDS);
- } catch (Exception e) {
- return false;
- }
+ return embedCartridgeWizardPage.processCartridges();
}
@Override
public void addPages() {
- addPage(new EmbedCartridgeWizardPage(wizardModel, this));
+ addPage(this.embedCartridgeWizardPage = new EmbedCartridgeWizardPage(wizardModel,
this));
}
public IApplication getApplication() {
Modified:
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 2011-11-21
12:44:41 UTC (rev 36480)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-21
12:57:31 UTC (rev 36481)
@@ -12,6 +12,8 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.TimeUnit;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -49,6 +51,7 @@
import org.jboss.tools.common.ui.WizardUtils;
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;
import org.jboss.tools.openshift.express.internal.ui.common.StringUtils;
@@ -131,27 +134,31 @@
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
- IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
- if (event.getChecked()) {
- if (IEmbeddableCartridge.PHPMYADMIN_34.equals(cartridge)) {
- addPhpMyAdminCartridge(cartridge);
- } else if (IEmbeddableCartridge.JENKINS_14.equals(cartridge)) {
- addJenkinsCartridge(cartridge);
+ try {
+ IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
+ if (event.getChecked()) {
+ if (IEmbeddableCartridge.PHPMYADMIN_34.equals(cartridge)) {
+ addPhpMyAdminCartridge(cartridge);
+ } else if (IEmbeddableCartridge.JENKINS_14.equals(cartridge)) {
+ addJenkinsCartridge(cartridge);
+ } else {
+ addCartridge(cartridge);
+ }
} else {
- addCartridge(cartridge);
+ if (IEmbeddableCartridge.MYSQL_51.equals(cartridge)) {
+ removeMySQLCartridge(cartridge);
+ } else {
+ removeCartridge(cartridge);
+ }
}
- } else {
- if (IEmbeddableCartridge.MYSQL_51.equals(cartridge)) {
- removeMySQLCartridge(cartridge);
- } else {
- removeCartridge(cartridge);
- }
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
}
}
};
}
- private void addJenkinsCartridge(final IEmbeddableCartridge cartridge) {
+ private void addJenkinsCartridge(final IEmbeddableCartridge cartridge) throws
OpenShiftException {
if (model.hasApplication(ICartridge.JENKINS_14)) {
model.getSelectedEmbeddableCartridges().add(cartridge);
} else {
@@ -191,7 +198,7 @@
}
}
- private void addPhpMyAdminCartridge(IEmbeddableCartridge cartridge) {
+ private void addPhpMyAdminCartridge(IEmbeddableCartridge cartridge) throws
OpenShiftException {
if (!viewer.getChecked(IEmbeddableCartridge.MYSQL_51)) {
if (MessageDialog.openQuestion(getShell(), "Embed mysql cartridge",
"To embed phpmyadmin, you'd also have to embed mysql.")) {
@@ -206,11 +213,11 @@
}
}
- private void addCartridge(IEmbeddableCartridge cartridge) {
+ private void addCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException {
model.getSelectedEmbeddableCartridges().add(cartridge);
}
- private void removeMySQLCartridge(IEmbeddableCartridge cartridge) {
+ private void removeMySQLCartridge(IEmbeddableCartridge cartridge) throws
OpenShiftException {
if (viewer.getChecked(IEmbeddableCartridge.PHPMYADMIN_34)) {
if (MessageDialog.openQuestion(getShell(), "Remove phpmyadmin cartridge",
"If you remove the mysql cartridge, you'd also have to remove
phpmyadmin.")) {
@@ -225,7 +232,7 @@
}
}
- private void removeCartridge(IEmbeddableCartridge cartridge) {
+ private void removeCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException
{
model.getSelectedEmbeddableCartridges().remove(cartridge);
}
@@ -235,7 +242,11 @@
@Override
public void widgetSelected(SelectionEvent e) {
viewer.setAllChecked(true);
- addJenkinsCartridge(IEmbeddableCartridge.JENKINS_14);
+ try {
+ addJenkinsCartridge(IEmbeddableCartridge.JENKINS_14);
+ } catch (OpenShiftException ex) {
+ OpenShiftUIActivator.log("Could not select jenkins cartridge", ex);
+ }
}
};
@@ -261,14 +272,7 @@
protected IStatus run(IProgressMonitor monitor) {
try {
setViewerInput(model.loadEmbeddableCartridges());
- model.initSelectedEmbeddableCartridges();
- getShell().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- viewer.setCheckedElements(model.getSelectedEmbeddableCartridges().toArray());
- }
- });
+ setViewerCheckedElements(model.getSelectedEmbeddableCartridges());
return Status.OK_STATUS;
} catch (Exception e) {
clearViewer();
@@ -286,6 +290,16 @@
setViewerInput(new ArrayList<IEmbeddableCartridge>());
}
+ private void setViewerCheckedElements(final Collection<IEmbeddableCartridge>
cartridges) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ viewer.setCheckedElements(cartridges.toArray());
+ }
+ });
+ }
+
private void setViewerInput(final Collection<IEmbeddableCartridge> cartridges) {
getShell().getDisplay().syncExec(new Runnable() {
@@ -348,4 +362,31 @@
}
+ public boolean processCartridges() {
+ final ArrayBlockingQueue<Boolean> queue = new
ArrayBlockingQueue<Boolean>(1);
+ try {
+ WizardUtils.runInWizard(
+ new Job(NLS.bind("Adding/Removing embedded cartridges for application
{0}...",
+ model.getApplication().getName())) {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ model.embedCartridges();
+ queue.offer(true);
+ } catch (OpenShiftException e) {
+ queue.offer(false);
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ NLS.bind("Could not embed cartridges to application {0}",
+ model.getApplication().getName()), e);
+ }
+ return Status.OK_STATUS;
+ }
+ }, getContainer());
+ return queue.poll(10, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
}
\ 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/EmbedCartridgeWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-21
12:44:41 UTC (rev 36480)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-21
12:57:31 UTC (rev 36481)
@@ -11,8 +11,14 @@
package org.jboss.tools.openshift.express.internal.ui.wizard;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
+import org.eclipse.core.databinding.observable.Diffs;
+import org.eclipse.core.databinding.observable.list.ListDiff;
+import org.eclipse.core.databinding.observable.list.ListDiffEntry;
+import org.eclipse.core.runtime.Assert;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.express.client.IApplication;
import org.jboss.tools.openshift.express.client.ICartridge;
@@ -34,21 +40,21 @@
private ApplicationWizardModel wizardModel;
private List<IEmbeddableCartridge> embeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
- private List<IEmbeddableCartridge> selectedEmbeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
+ private List<IEmbeddableCartridge> selectedCartridges;
public EmbedCartridgeWizardPageModel(ApplicationWizardModel wizardModel) {
this.wizardModel = wizardModel;
- wizardModel.setSelectedCartridges(selectedEmbeddableCartridges);
}
- public void initSelectedEmbeddableCartridges() throws OpenShiftException {
+ public void loadSelectedEmbeddableCartridges() throws OpenShiftException {
+ selectedCartridges = new ArrayList<IEmbeddableCartridge>();
IApplication application = wizardModel.getApplication();
if (application == null
|| application.getEmbeddedCartridges() == null) {
return;
}
List<IEmbeddableCartridge> embeddedCartridges =
application.getEmbeddedCartridges();
- getSelectedEmbeddableCartridges().addAll(embeddedCartridges);
+ selectedCartridges.addAll(embeddedCartridges);
}
public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws
OpenShiftException {
@@ -66,8 +72,11 @@
return embeddableCartridges;
}
- public List<IEmbeddableCartridge> getSelectedEmbeddableCartridges() {
- return selectedEmbeddableCartridges;
+ public List<IEmbeddableCartridge> getSelectedEmbeddableCartridges() throws
OpenShiftException {
+ if (selectedCartridges == null) {
+ loadSelectedEmbeddableCartridges();
+ }
+ return selectedCartridges;
}
public boolean hasApplication(ICartridge cartridge) {
@@ -80,7 +89,66 @@
}
}
+ public IApplication getApplication() {
+ return wizardModel.getApplication();
+ }
+
public void createJenkinsApplication(String name) throws OpenShiftException {
wizardModel.getUser().createApplication(name, ICartridge.JENKINS_14);
}
+
+ public void embedCartridges() throws OpenShiftException {
+ if (selectedCartridges == null) {
+ return;
+ }
+ List<IEmbeddableCartridge> addedCartridges = new
ArrayList<IEmbeddableCartridge>();
+ List<IEmbeddableCartridge> removedCartridges = new
ArrayList<IEmbeddableCartridge>();
+ computeAdditionsAndRemovals(addedCartridges, removedCartridges, selectedCartridges);
+ addEmbeddedCartridges(addedCartridges);
+ removeEmbeddedCartridges(removedCartridges);
+ }
+
+ private void removeEmbeddedCartridges(List<IEmbeddableCartridge>
removedCartridges) throws OpenShiftException {
+ if (removedCartridges.isEmpty()) {
+ return;
+ }
+ Collections.sort(removedCartridges, new CartridgeComparator());
+ getApplication().removeEmbbedCartridges(removedCartridges);
+ }
+
+ private void addEmbeddedCartridges(List<IEmbeddableCartridge> addedCartridges)
throws OpenShiftException {
+ if (addedCartridges.isEmpty()) {
+ return;
+ }
+ Collections.sort(addedCartridges, new CartridgeComparator());
+ getApplication().addEmbbedCartridges(addedCartridges);
+ }
+
+ private void computeAdditionsAndRemovals(List<IEmbeddableCartridge>
addedCartridges,
+ List<IEmbeddableCartridge> removedCartridges, List<IEmbeddableCartridge>
selectedCartridges)
+ throws OpenShiftException {
+ ListDiff listDiff = Diffs.computeListDiff(getApplication().getEmbeddedCartridges(),
selectedCartridges);
+ for (ListDiffEntry entry : listDiff.getDifferences()) {
+ if (entry.isAddition()) {
+ addedCartridges.add((IEmbeddableCartridge) entry.getElement());
+ } else {
+ removedCartridges.add((IEmbeddableCartridge) entry.getElement());
+ }
+ }
+ }
+
+ private static class CartridgeComparator implements
Comparator<IEmbeddableCartridge> {
+
+ @Override
+ public int compare(IEmbeddableCartridge thisCartridge, IEmbeddableCartridge
thatCartridge) {
+ // mysql has to be added/removed before phpmyadmin
+ if (thisCartridge.equals(IEmbeddableCartridge.MYSQL_51)) {
+ return -1;
+ } else if (thatCartridge.equals(IEmbeddableCartridge.MYSQL_51)) {
+ return 1;
+ }
+ return 0;
+ }
+ }
+
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizard.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizard.java 2011-11-21
12:44:41 UTC (rev 36480)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizard.java 2011-11-21
12:57:31 UTC (rev 36481)
@@ -10,20 +10,9 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-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.wizard.Wizard;
-import org.eclipse.osgi.util.NLS;
-import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.openshift.express.client.IApplication;
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
@@ -31,6 +20,8 @@
public class NewApplicationWizard extends Wizard {
private ApplicationWizardModel wizardModel;
+ private NewApplicationWizardPage applicationPage;
+ private EmbedCartridgeWizardPage embedCartridgePage;
public NewApplicationWizard(IUser user) {
this.wizardModel = new ApplicationWizardModel(user);
@@ -39,33 +30,20 @@
@Override
public boolean performFinish() {
- final ArrayBlockingQueue<Boolean> queue = new
ArrayBlockingQueue<Boolean>(1);
- try {
- WizardUtils.runInWizard(new Job(NLS.bind("Creating application
\"{0}\"...", wizardModel.getName())) {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- wizardModel.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}\"",
wizardModel.getName()), e);
- }
- return Status.OK_STATUS;
- }
- }, getContainer());
- return queue.poll(10, TimeUnit.SECONDS);
- } catch (Exception e) {
- return false;
+ boolean successfull = true;
+ if (wizardModel.getApplication() == null) {
+ successfull = applicationPage.createApplication();
}
+ if (successfull) {
+ successfull = embedCartridgePage.processCartridges();
+ }
+ return successfull;
}
@Override
public void addPages() {
- addPage(new NewApplicationWizardPage(wizardModel, this));
- addPage(new EmbedCartridgeWizardPage(wizardModel, this));
+ addPage(this.applicationPage = new NewApplicationWizardPage(wizardModel, this));
+ addPage(this.embedCartridgePage = new EmbedCartridgeWizardPage(wizardModel, this));
}
public IApplication getApplication() {
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-21
12:44:41 UTC (rev 36480)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-11-21
12:57:31 UTC (rev 36481)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
+import java.util.concurrent.ArrayBlockingQueue;
+
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateListStrategy;
@@ -49,8 +51,8 @@
private ApplicationWizardModel wizardModel;
public NewApplicationWizardPage(ApplicationWizardModel wizardModel, IWizard wizard) {
- super("Create new OpenShift Express application", "Create new OpenShift
Express application",
- "Create new OpenShift Express application", wizard);
+ super("New OpenShift Express Application", "Select a name and an type
for your new OpenShift Express application",
+ "NewOpenShiftExpressApplication", wizard);
this.wizardModel = wizardModel;
this.model = new NewApplicationWizardPageModel(wizardModel);
}
@@ -151,9 +153,16 @@
}
}
-
@Override
protected void onPageWillGetDeactivated(Direction progress, final PageChangingEvent
event, DataBindingContext dbc) {
+ boolean applicationCreated = createApplication();
+ if (!applicationCreated) {
+ event.doit = false;
+ }
+ }
+
+ public boolean createApplication() {
+ final ArrayBlockingQueue<Boolean> applicationCreated = new
ArrayBlockingQueue<Boolean>(1);
try {
WizardUtils.runInWizard(new Job(NLS.bind("Creating application
\"{0}\"...", wizardModel.getName())) {
@@ -161,16 +170,19 @@
protected IStatus run(IProgressMonitor monitor) {
try {
wizardModel.createApplication();
+ applicationCreated.offer(true);
+ return Status.OK_STATUS;
} catch (OpenShiftException e) {
- event.doit = false;
- return OpenShiftUIActivator.createErrorStatus("Could not create application
\"{0}\"", e, wizardModel.getName());
+ applicationCreated.offer(false);
+ return OpenShiftUIActivator.createErrorStatus("Could not create application
\"{0}\"", e,
+ wizardModel.getName());
}
- return Status.OK_STATUS;
}
}, getContainer());
} catch (Exception e) {
// ignore
}
+ return applicationCreated.poll();
}
private class ApplicationNameValidator implements IValidator {