Author: adietish
Date: 2011-11-18 12:12:23 -0500 (Fri, 18 Nov 2011)
New Revision: 36449
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
Log:
[JBIDE-9927] set a custom ElmenentComparer to the viewer since the available cartridges
(items listed in the viewer) are not the same instances as the cartridges embedded into
the application (items to be checked in the viewer)
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:43:24 UTC (rev 36448)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-18
17:12:23 UTC (rev 36449)
@@ -12,7 +12,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -32,6 +31,7 @@
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerCell;
@@ -103,6 +103,7 @@
TableColumnLayout tableLayout = new TableColumnLayout();
tableContainer.setLayout(tableLayout);
CheckboxTableViewer viewer = new CheckboxTableViewer(table);
+ viewer.setComparer(new EqualityComparer());
viewer.setContentProvider(new ArrayContentProvider());
createTableColumn("Embeddable Cartridge", 1, new CellLabelProvider() {
@@ -262,22 +263,11 @@
setViewerInput(model.loadEmbeddableCartridges());
model.initSelectedEmbeddableCartridges();
getShell().getDisplay().syncExec(new Runnable() {
-
+
@Override
public void run() {
- viewer.setCheckedElements(
- getViewerInstances(model.getSelectedEmbeddableCartridges()));
+ viewer.setCheckedElements(model.getSelectedEmbeddableCartridges().toArray());
}
-
- 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) {
@@ -291,7 +281,7 @@
// ignore
}
}
-
+
private void clearViewer() {
setViewerInput(new ArrayList<IEmbeddableCartridge>());
}
@@ -328,4 +318,34 @@
}
}
+ /**
+ * Viewer element comparer based on #equals(). The default implementation in
+ * CheckboxTableViewer compares elements based on instance identity.
+ * <p>
+ * We need this since the available cartridges (item listed in the viewer)
+ * are not the same instance as the ones in the embedded application (items
+ * to check in the viewer).
+ */
+ private static class EqualityComparer implements IElementComparer {
+
+ @Override
+ public boolean equals(Object thisObject, Object thatObject) {
+ if (thisObject == null) {
+ return thatObject != null;
+ }
+
+ if (thatObject == null) {
+ return false;
+ }
+
+ return thisObject.equals(thatObject);
+ }
+
+ @Override
+ public int hashCode(Object element) {
+ return element.hashCode();
+ }
+
+ }
+
}
\ No newline at end of file