Author: adietish
Date: 2011-11-18 11:21:33 -0500 (Fri, 18 Nov 2011)
New Revision: 36442
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/ApplicationWizardPage.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
Log:
[JBIDE-9927] embedded cartridges are now correctly checked when the dialog is shown
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-18
16:20:53 UTC (rev 36441)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java 2011-11-18
16:21:33 UTC (rev 36442)
@@ -10,9 +10,19 @@
******************************************************************************/
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;
@@ -27,8 +37,14 @@
private IApplication application;
private String name;
private ICartridge cartridge;
+ private List<IEmbeddableCartridge> selectedCartridges;
public ApplicationWizardModel(IUser user) {
+ this(null, user);
+ }
+
+ public ApplicationWizardModel(IApplication application, IUser user) {
+ this.application = application;
this.user = user;
}
@@ -49,10 +65,10 @@
}
public void createApplication() throws OpenShiftException {
- createApplication(name, cartridge);
+ IApplication application = createApplication(name, cartridge);
+ setApplication(application);
}
-
public void setApplication(IApplication application) {
firePropertyChange(PROPERTY_APPLICATION, this.application, this.application =
application);
}
@@ -61,9 +77,64 @@
return application;
}
- public void createApplication(String name, ICartridge cartridge) throws
OpenShiftException {
- IApplication application = getUser().createApplication(name, cartridge);
- setApplication(application);
+ 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/ApplicationWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java 2011-11-18
16:20:53 UTC (rev 36441)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java 2011-11-18
16:21:33 UTC (rev 36442)
@@ -329,7 +329,7 @@
@Override
public void widgetSelected(SelectionEvent e) {
- WizardUtils.openWizardDialog(new EmbedCartridgeWizard(model.getUser()), getShell());
+ WizardUtils.openWizardDialog(new EmbedCartridgeWizard(model.getSelectedApplication(),
model.getUser()), getShell());
}
};
}
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-18
16:20:53 UTC (rev 36441)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java 2011-11-18
16:21:33 UTC (rev 36442)
@@ -32,8 +32,8 @@
private ApplicationWizardModel wizardModel;
- public EmbedCartridgeWizard(IUser user) {
- this.wizardModel = new ApplicationWizardModel(user);
+ public EmbedCartridgeWizard(IApplication application, IUser user) {
+ this.wizardModel = new ApplicationWizardModel(application, user);
setNeedsProgressMonitor(true);
}
@@ -41,21 +41,24 @@
public boolean performFinish() {
final ArrayBlockingQueue<Boolean> queue = new
ArrayBlockingQueue<Boolean>(1);
try {
- WizardUtils.runInWizard(new Job(NLS.bind("Creating application
\"{0}\"...", wizardModel.getName())) {
+ WizardUtils.runInWizard(
+ new Job(NLS.bind("Embedding cartridges to application
\"{0}\"...",
+ wizardModel.getApplication().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());
+ @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;
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-18
16:20:53 UTC (rev 36441)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-18
16:21:33 UTC (rev 36442)
@@ -133,9 +133,11 @@
IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
if (event.getChecked()) {
if (IEmbeddableCartridge.PHPMYADMIN_34.equals(cartridge)) {
- addPhpMyACartridge(cartridge);
+ addPhpMyAdminCartridge(cartridge);
} else if (IEmbeddableCartridge.JENKINS_14.equals(cartridge)) {
addJenkinsCartridge(cartridge);
+ } else {
+ addCartridge(cartridge);
}
} else {
model.getSelectedEmbeddableCartridges().remove(cartridge);
@@ -159,6 +161,7 @@
protected IStatus run(IProgressMonitor monitor) {
try {
model.createJenkinsApplication(name);
+ model.getSelectedEmbeddableCartridges().add(cartridge);
return Status.OK_STATUS;
} catch (Exception e) {
getShell().getDisplay().syncExec(new Runnable() {
@@ -183,19 +186,25 @@
}
}
- private void addPhpMyACartridge(IEmbeddableCartridge cartridge) {
- if (MessageDialog.openQuestion(getShell(), "Enable MySQL cartridge",
- "To embed PhpMyAdmin, you'd also have to embed MySql. ")) {
- List<IEmbeddableCartridge> selectedCartriges =
model.getSelectedEmbeddableCartridges();
- viewer.setChecked(IEmbeddableCartridge.MYSQL_51, true);
- selectedCartriges.add(IEmbeddableCartridge.MYSQL_51);
- selectedCartriges.add(cartridge);
+ private void addPhpMyAdminCartridge(IEmbeddableCartridge cartridge) {
+ if (!viewer.getChecked(IEmbeddableCartridge.MYSQL_51)) {
+ if (MessageDialog.openQuestion(getShell(), "Enable MySQL cartridge",
+ "To embed PhpMyAdmin, you'd also have to embed MySql. ")) {
+ viewer.setChecked(IEmbeddableCartridge.MYSQL_51, true);
+ model.getSelectedEmbeddableCartridges().add(IEmbeddableCartridge.MYSQL_51);
+ model.getSelectedEmbeddableCartridges().add(cartridge);
+ } else {
+ viewer.setChecked(cartridge, false);
+ }
} else {
- viewer.setChecked(cartridge, false);
+ model.getSelectedEmbeddableCartridges().add(cartridge);
}
- refreshViewer();
}
+ private void addCartridge(IEmbeddableCartridge cartridge) {
+ model.getSelectedEmbeddableCartridges().add(cartridge);
+ }
+
private SelectionListener onCheckAll() {
return new SelectionAdapter() {
@@ -228,6 +237,25 @@
protected IStatus run(IProgressMonitor monitor) {
try {
setViewerInput(model.loadEmbeddableCartridges());
+ model.initSelectedEmbeddableCartridges();
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ viewer.setCheckedElements(
+ getViewerInstances(model.getSelectedEmbeddableCartridges()));
+ }
+
+ private Object[] getViewerInstances(List<IEmbeddableCartridge>
selectedEmbeddableCartridges) {
+ List<IEmbeddableCartridge> viewerInstances = new
ArrayList<IEmbeddableCartridge>();
+ for (IEmbeddableCartridge cartridge : model.getEmbeddableCartridges()) {
+ if (selectedEmbeddableCartridges.contains(cartridge)) {
+ viewerInstances.add(cartridge);
+ }
+ }
+ return viewerInstances.toArray();
+ }
+ });
return Status.OK_STATUS;
} catch (Exception e) {
clearViewer();
@@ -240,7 +268,7 @@
// ignore
}
}
-
+
private void clearViewer() {
setViewerInput(new ArrayList<IEmbeddableCartridge>());
}
@@ -255,16 +283,6 @@
});
}
- private void refreshViewer() {
- getShell().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- viewer.refresh(true, true);
- }
- });
- }
-
private static class JenkinsApplicationDialog extends InputDialog {
public JenkinsApplicationDialog(Shell shell) {
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-18
16:20:53 UTC (rev 36441)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-18
16:21:33 UTC (rev 36442)
@@ -38,8 +38,19 @@
public EmbedCartridgeWizardPageModel(ApplicationWizardModel wizardModel) {
this.wizardModel = wizardModel;
+ wizardModel.setSelectedCartridges(selectedEmbeddableCartridges);
}
+ public void initSelectedEmbeddableCartridges() throws OpenShiftException {
+ IApplication application = wizardModel.getApplication();
+ if (application == null
+ || application.getEmbeddedCartridges() == null) {
+ return;
+ }
+ List<IEmbeddableCartridge> embeddedCartridges =
application.getEmbeddedCartridges();
+ getSelectedEmbeddableCartridges().addAll(embeddedCartridges);
+ }
+
public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws
OpenShiftException {
List<IEmbeddableCartridge> cartridges =
wizardModel.getUser().getEmbeddableCartridges();
setEmbeddableCartridges(cartridges);
@@ -58,7 +69,7 @@
public List<IEmbeddableCartridge> getSelectedEmbeddableCartridges() {
return selectedEmbeddableCartridges;
}
-
+
public boolean hasApplication(ICartridge cartridge) {
try {
return wizardModel.getUser().hasApplication(cartridge);
@@ -70,6 +81,6 @@
}
public void createJenkinsApplication(String name) throws OpenShiftException {
- IApplication application = wizardModel.getUser().createApplication(name,
ICartridge.JENKINS_14);
+ wizardModel.getUser().createApplication(name, ICartridge.JENKINS_14);
}
}