JBoss Tools SVN: r27167 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 14:13:50 -0500 (Fri, 03 Dec 2010)
New Revision: 27167
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
Log:
[JBIDE-7688]
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-03 19:13:35 UTC (rev 27166)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-03 19:13:50 UTC (rev 27167)
@@ -1,5 +1,19 @@
2010-12-03 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java (filter):
+ * src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java (filter):
+ [JBIDE-7688] remove duplicate code and delegate to filter
+ * src/org/jboss/tools/deltacloud/ui/views/InstanceView.java:
+ * src/org/jboss/tools/deltacloud/ui/views/ImageView.java:
+ * src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java:
+ [JBIDE-7688] provide common superclass for ImageView and InstanceView
+ * src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java:
+ * src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java:
+ * src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java:
+ [JBIDE-7688] provide common superclass for ImageViewContentAndLabelProvider and InstanceViewContentAndLabelProvider
+ * src/org/jboss/tools/deltacloud/ui/commands/FilterInstancesHandler.java:
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/InstanceFilterWizard.java:
+ [JBIDE-7688] renamed InstanceFilter to InstanceFilterWizard since it is a wizard (and shall not be mixed up with the filter IntanceFilter)
* src/org/jboss/tools/deltacloud/ui/views/AbstractCloudChildrenTableView.java:
[JBIDE-7790] corrected storage & retrieval of selected cloud in the preferences
[JBIDE-7149] added listener to gloabl selection, changing selected cloud in instance- and image-view accordingly
14 years
JBoss Tools SVN: r27166 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 14:13:35 -0500 (Fri, 03 Dec 2010)
New Revision: 27166
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java
Log:
[JBIDE-7688] remove duplicate code and delegate to filter
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java 2010-12-03 19:11:47 UTC (rev 27165)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java 2010-12-03 19:13:35 UTC (rev 27166)
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
-import java.util.ArrayList;
-
import org.eclipse.jface.viewers.TreeViewer;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudImage;
@@ -77,17 +75,10 @@
// refresh();
}
- public DeltaCloudImage[] filter(DeltaCloudImage[] input) {
- ArrayList<DeltaCloudImage> array = new ArrayList<DeltaCloudImage>();
+ public DeltaCloudImage[] filter(DeltaCloudImage[] images) {
DeltaCloud cloud = (DeltaCloud) getElement();
IImageFilter f = cloud.getImageFilter();
- for (int i = 0; i < input.length; ++i) {
- DeltaCloudImage image = input[i];
- if (f.isVisible(image))
- array.add(image);
- }
- return array.toArray(new DeltaCloudImage[array.size()]);
-
+ return f.filter(images).toArray(new DeltaCloudImage[images.length]);
}
protected void dispose() {
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java 2010-12-03 19:11:47 UTC (rev 27165)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java 2010-12-03 19:13:35 UTC (rev 27166)
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
-import java.util.ArrayList;
-
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Display;
import org.jboss.tools.deltacloud.core.DeltaCloud;
@@ -85,16 +83,10 @@
// refresh();
}
- private DeltaCloudInstance[] filter(DeltaCloudInstance[] input) {
- ArrayList<DeltaCloudInstance> array = new ArrayList<DeltaCloudInstance>();
+ public DeltaCloudInstance[] filter(DeltaCloudInstance[] instances) {
DeltaCloud cloud = (DeltaCloud) getElement();
IInstanceFilter f = cloud.getInstanceFilter();
- for (int i = 0; i < input.length; ++i) {
- DeltaCloudInstance instance = input[i];
- if (f.isVisible(instance))
- array.add(instance);
- }
- return array.toArray(new DeltaCloudInstance[array.size()]);
+ return f.filter(instances).toArray(new DeltaCloudInstance[instances.length]);
}
protected void dispose() {
14 years
JBoss Tools SVN: r27165 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 14:11:47 -0500 (Fri, 03 Dec 2010)
New Revision: 27165
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudChildrenTableView.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
Log:
[JBIDE-7688] provide common superclass for ImageView and InstanceView
Deleted: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudChildrenTableView.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudChildrenTableView.java 2010-12-03 19:07:50 UTC (rev 27164)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudChildrenTableView.java 2010-12-03 19:11:47 UTC (rev 27165)
@@ -1,432 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat Inc..
- * All rights reserved. This program and the accompanying materials
- * are 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 Incorporated - initial API and implementation
- *******************************************************************************/
-package org.jboss.tools.deltacloud.ui.views;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.layout.TableColumnLayout;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.TableViewer;
-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.VerifyEvent;
-import org.eclipse.swt.events.VerifyListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.ui.ISelectionListener;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.ViewPart;
-import org.jboss.tools.deltacloud.core.DeltaCloud;
-import org.jboss.tools.deltacloud.core.DeltaCloudException;
-import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
-import org.jboss.tools.deltacloud.core.DeltaCloudManager;
-import org.jboss.tools.deltacloud.core.ICloudManagerListener;
-import org.jboss.tools.deltacloud.core.IInstanceFilter;
-import org.jboss.tools.deltacloud.ui.Activator;
-import org.jboss.tools.deltacloud.ui.ErrorUtils;
-import org.jboss.tools.internal.deltacloud.ui.preferences.TextPreferenceValue;
-import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
-
-/**
- * @author Jeff Johnston
- * @author Andre Dietisheim
- */
-public abstract class AbstractCloudChildrenTableView<T> extends ViewPart implements ICloudManagerListener {
-
- private final static String CLOUD_SELECTOR_LABEL = "CloudSelector.label"; //$NON-NLS-1$
-
- private static final String FILTERED_LABEL = "Filtered.label"; //$NON-NLS-1$
- private static final String FILTERED_TOOLTIP = "FilteredImages.tooltip"; //$NON-NLS-1$
-
- private Combo currentCloudSelector;
- private Label currentCloudSelectorLabel;
- private TableViewer viewer;
-
- private DeltaCloud currentCloud;
-
- private TextPreferenceValue lastSelectedCloudPref;
-
- private ModifyListener cloudModifyListener = new ModifyListener() {
-
- @Override
- public void modifyText(ModifyEvent e) {
- int index = currentCloudSelector.getSelectionIndex();
- if (index < 0) {
- return;
- }
-
- removeListener(currentCloud);
-
- final DeltaCloud currentCloud = getCurrentCloud(index);
- if (currentCloud != null) {
- lastSelectedCloudPref.store(currentCloud.getName());
- Display.getCurrent().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- setViewerInput(currentCloud);
- addListener(currentCloud);
- }
- });
- }
- }
- };
-
- private ISelectionListener workbenchSelectionListener = new ISelectionListener() {
-
- @Override
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- DeltaCloud cloud = UIUtils.getFirstAdaptedElement(selection, DeltaCloud.class);
- if (cloud != null) {
- currentCloudSelector.select(getIndexInClouds(cloud, getClouds()));
- }
- }
- };
-
- public AbstractCloudChildrenTableView() {
- lastSelectedCloudPref = new TextPreferenceValue(getSelectedCloudPrefsKey(), Activator.getDefault());
- }
-
- private class ColumnListener extends SelectionAdapter {
-
- private int column;
-
- public ColumnListener(int column) {
- this.column = column;
- }
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- TableViewerColumnComparator comparator = (TableViewerColumnComparator) viewer.getComparator();
- Table t = viewer.getTable();
- if (comparator.getColumn() == column) {
- comparator.reverseDirection();
- }
- comparator.setColumn(column);
- TableColumn tc = (TableColumn) e.getSource();
- t.setSortColumn(tc);
- t.setSortDirection(SWT.NONE);
- viewer.refresh();
- }
- };
-
- protected abstract String getSelectedCloudPrefsKey();
-
- protected abstract void addListener(DeltaCloud cloud);
-
- protected abstract void removeListener(DeltaCloud cloud);
-
- @Override
- public void dispose() {
- for (DeltaCloud cloud : getClouds()) {
- removeListener(cloud);
- }
- DeltaCloudManager.getDefault().removeCloudManagerListener(this);
- super.dispose();
- }
-
- @Override
- public void createPartControl(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
- FormLayout layout = new FormLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- container.setLayout(layout);
-
- DeltaCloud[] clouds = getClouds();
-
- createCloudSelector(container);
-
- initCloudSelector(lastSelectedCloudPref.get(null), currentCloudSelector, clouds);
-
- Label filterLabel = new Label(container, SWT.NULL);
- filterLabel.setText(CVMessages.getString(FILTERED_LABEL));
- filterLabel.setToolTipText(CVMessages.getString(FILTERED_TOOLTIP));
-
- Composite tableArea = new Composite(container, SWT.NULL);
- viewer = createTableViewer(tableArea);
-
- currentCloud = getCurrentCloud(currentCloudSelector.getSelectionIndex(), clouds);
-
- addListener(currentCloud);
- setViewerInput(currentCloud);
- setFilterLabelVisible(currentCloud, filterLabel);
-
- Point p1 = currentCloudSelectorLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- Point p2 = currentCloudSelector.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- int centering = (p2.y - p1.y + 1) / 2;
-
- FormData f = new FormData();
- f.top = new FormAttachment(0, 5 + centering);
- f.left = new FormAttachment(0, 30);
- currentCloudSelectorLabel.setLayoutData(f);
-
- f = new FormData();
- f.top = new FormAttachment(0, 5);
- f.left = new FormAttachment(currentCloudSelectorLabel, 5);
- currentCloudSelector.setLayoutData(f);
-
- f = new FormData();
- f.top = new FormAttachment(0, 5 + centering);
- f.right = new FormAttachment(100, -10);
- filterLabel.setLayoutData(f);
-
- f = new FormData();
- f.top = new FormAttachment(currentCloudSelector, 8);
- f.left = new FormAttachment(0, 0);
- f.right = new FormAttachment(100, 0);
- f.bottom = new FormAttachment(100, 0);
- tableArea.setLayoutData(f);
-
- // Create the help context id for the viewer's control
- PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.jboss.tools.deltacloud.ui.viewer");
- hookContextMenu(viewer.getControl());
- getSite().setSelectionProvider(viewer);
- getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(workbenchSelectionListener);
-
- DeltaCloudManager.getDefault().addCloudManagerListener(this);
- }
-
- private TableViewer createTableViewer(Composite tableArea) {
- TableColumnLayout tableLayout = new TableColumnLayout();
- tableArea.setLayout(tableLayout);
-
- TableViewer viewer = new TableViewer(tableArea,
- SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI);
- Table table = viewer.getTable();
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
- ITableContentAndLabelProvider provider = getContentAndLabelProvider();
- viewer.setContentProvider(provider);
- viewer.setLabelProvider(provider);
- createColumns(tableLayout, table);
-
- viewer.setComparator(new TableViewerColumnComparator());
- table.setSortDirection(SWT.NONE);
-
- return viewer;
- }
-
- protected abstract ITableContentAndLabelProvider getContentAndLabelProvider();
-
- private void setViewerInput(DeltaCloud currentCloud) {
- if (currentCloud != null) {
- viewer.setInput(currentCloud);
- }
- }
-
- protected void setViewerInput(T[] input) {
- viewer.setInput(input);
- }
-
- /**
- * Gets the clouds that are available in the model.
- *
- * @return the clouds
- */
- private DeltaCloud[] getClouds() {
- DeltaCloud[] clouds = new DeltaCloud[] {};
- try {
- clouds = DeltaCloudManager.getDefault().getClouds();
- } catch (DeltaCloudException e) {
- // TODO: internationalize strings
- ErrorUtils.handleError(
- "Error",
- "Could not get all clouds",
- e, Display.getDefault().getActiveShell());
- }
- return clouds;
- }
-
- private DeltaCloud getCurrentCloud(int index) {
- DeltaCloud[] clouds = getClouds();
- if (index < 0 || index >= clouds.length) {
- return null;
- } else {
- return clouds[index];
- }
- }
-
- private int getIndexInClouds(DeltaCloud cloudToSelect, DeltaCloud[] clouds) {
- if (cloudToSelect == null) {
- return 0;
- }
- return getCurrentCloud(cloudToSelect.getName(), clouds);
- }
-
- private int getCurrentCloud(String cloudName, DeltaCloud[] clouds) {
- int index = 0;
- if (cloudName != null && clouds.length > 0) {
- for (int i = 0; i < clouds.length; i++) {
- DeltaCloud cloud = clouds[i];
- if (cloudName != null && cloudName.equals(cloud.getName())) {
- index = i;
- break;
- }
- }
- }
- return index;
- }
-
- private void setFilterLabelVisible(DeltaCloud currentCloud, Label filterLabel) {
- if (currentCloud == null) {
- filterLabel.setVisible(false);
- return;
- }
-
- IInstanceFilter filter = currentCloud.getInstanceFilter();
- filterLabel.setVisible(!filter.toString().equals(IInstanceFilter.ALL_STRING));
- }
-
- private DeltaCloud getCurrentCloud(int selectedCloudIndex, DeltaCloud[] clouds) {
- if (selectedCloudIndex < 0) {
- return null;
- }
-
- return clouds[selectedCloudIndex];
- }
-
- private void createColumns(TableColumnLayout tableLayout, Table table) {
- for (int i = 0; i < InstanceViewLabelAndContentProvider.Column.getSize(); ++i) {
- InstanceViewLabelAndContentProvider.Column c =
- InstanceViewLabelAndContentProvider.Column.getColumn(i);
- TableColumn tc = new TableColumn(table, SWT.NONE);
- if (i == 0) {
- table.setSortColumn(tc);
- }
- tc.setText(CVMessages.getString(c.name()));
- tableLayout.setColumnData(tc, new ColumnWeightData(c.getWeight(), true));
- tc.addSelectionListener(new ColumnListener(i));
- }
- }
-
- private void createCloudSelector(Composite parent) {
- this.currentCloudSelectorLabel = new Label(parent, SWT.NULL);
- currentCloudSelectorLabel.setText(CVMessages.getString(CLOUD_SELECTOR_LABEL));
-
- this.currentCloudSelector = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
- currentCloudSelector.addModifyListener(cloudModifyListener);
- // Following is a kludge so that on Linux the Combo is read-only but
- // has a white background.
- currentCloudSelector.addVerifyListener(new VerifyListener() {
- @Override
- public void verifyText(VerifyEvent e) {
- e.doit = false;
- }
- });
- }
-
- private void hookContextMenu(Control control) {
- IMenuManager contextMenu = UIUtils.createContextMenu(control);
- UIUtils.registerContributionManager(UIUtils.getContextMenuId(getViewID()), contextMenu, control);
- }
-
- protected abstract String getViewID();
-
- private void initCloudSelector(String cloudToSelect, Combo cloudSelector, DeltaCloud[] clouds) {
- int selectedIndex = 0;
- String[] cloudNames = new String[clouds.length];
- for (int i = 0; i < clouds.length; ++i) {
- cloudNames[i] = clouds[i].getName();
- if (cloudNames[i].equals(cloudToSelect))
- selectedIndex = i;
- }
- if (cloudNames.length > 0) {
- cloudSelector.setItems(cloudNames);
- cloudSelector.setText(cloudNames[selectedIndex]);
- }
- }
-
- public void cloudsChanged(int type) {
- int currIndex = 0;
- if (currentCloud != null) {
- currIndex = currentCloudSelector.getSelectionIndex();
- }
- DeltaCloud[] clouds = getClouds();
- int index = getIndexInClouds(currentCloud, getClouds());
- if (type == ICloudManagerListener.RENAME_EVENT) {
- index = currIndex; // no change in cloud displayed
- }
-
- String[] cloudNames = toCloudNames(clouds);
- setCloudSelectorItems(cloudNames);
- this.currentCloud = getCurrentCloud(index);
-
- if (cloudNames.length > 0) {
- currentCloudSelector.setText(cloudNames[index]);
- viewer.setInput(currentCloud);
- } else {
- currentCloudSelector.setText("");
- viewer.setInput(new DeltaCloudInstance[0]);
- }
- }
-
- private String[] toCloudNames(DeltaCloud[] clouds) {
- List<String> cloudNames = new ArrayList<String>();
- for (DeltaCloud cloud : clouds) {
- if (cloud != null) {
- cloudNames.add(cloud.getName());
- }
- }
- return (String[]) cloudNames.toArray(new String[cloudNames.size()]);
- }
-
- private void setCloudSelectorItems(String[] cloudNames) {
- currentCloudSelector.removeModifyListener(cloudModifyListener);
- currentCloudSelector.setItems(cloudNames);
- currentCloudSelector.addModifyListener(cloudModifyListener);
- }
-
- /**
- * Refresh the states of the commands in the toolbar.
- */
- protected abstract void refreshToolbarCommandStates();
-
- public void listChanged(final DeltaCloud cloud, final T[] cloudChildren) {
- // Run following under Display thread since this can be
- // triggered by a non-display thread notifying listeners.
- if (cloud != null
- && currentCloud != null
- && cloud.getName().equals(currentCloud.getName())) {
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- // does not add identical instance twice
- addListener(cloud);
- setViewerInput(cloudChildren);
- refreshToolbarCommandStates();
- }
- });
- }
- }
-
- @Override
- public void setFocus() {
- viewer.getControl().setFocus();
- }
-
-}
Copied: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java (from rev 27137, trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudChildrenTableView.java)
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java (rev 0)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java 2010-12-03 19:11:47 UTC (rev 27165)
@@ -0,0 +1,432 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are 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 Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.ui.views;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.action.IMenuManager;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TableViewer;
+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.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
+import org.jboss.tools.deltacloud.core.DeltaCloudManager;
+import org.jboss.tools.deltacloud.core.ICloudManagerListener;
+import org.jboss.tools.deltacloud.core.IDeltaCloudElement;
+import org.jboss.tools.deltacloud.core.IInstanceFilter;
+import org.jboss.tools.deltacloud.ui.Activator;
+import org.jboss.tools.deltacloud.ui.ErrorUtils;
+import org.jboss.tools.internal.deltacloud.ui.preferences.TextPreferenceValue;
+import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
+
+/**
+ * A common superclass for viewers that operate on IDeltaCloudElements
+ * (currently DeltaCloudImage and DeltaCloudInstance)
+ *
+ * @see InstanceView
+ * @see ImageView
+ *
+ * @author Jeff Johnston
+ * @author Andre Dietisheim
+ */
+public abstract class AbstractCloudElementTableView<CLOUDELEMENT extends IDeltaCloudElement> extends ViewPart implements
+ ICloudManagerListener {
+
+ private final static String CLOUD_SELECTOR_LABEL = "CloudSelector.label"; //$NON-NLS-1$
+
+ private static final String FILTERED_LABEL = "Filtered.label"; //$NON-NLS-1$
+ private static final String FILTERED_TOOLTIP = "FilteredImages.tooltip"; //$NON-NLS-1$
+
+ private Combo currentCloudSelector;
+ private Label currentCloudSelectorLabel;
+ private TableViewer viewer;
+
+ private DeltaCloud currentCloud;
+
+ private TextPreferenceValue lastSelectedCloudPref;
+
+ private ModifyListener cloudModifyListener = new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ int index = currentCloudSelector.getSelectionIndex();
+ if (index < 0) {
+ return;
+ }
+
+ removeListener(currentCloud);
+
+ AbstractCloudElementTableView.this.currentCloud = getCurrentCloud(index, getClouds());
+ if (currentCloud != null) {
+ lastSelectedCloudPref.store(currentCloud.getName());
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ setViewerInput(currentCloud);
+ addListener(currentCloud);
+ }
+ });
+ }
+ }
+ };
+
+ private ISelectionListener workbenchSelectionListener = new ISelectionListener() {
+
+ @Override
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ DeltaCloud cloud = UIUtils.getFirstAdaptedElement(selection, DeltaCloud.class);
+ if (cloud != null) {
+ currentCloudSelector.select(getCloudIndex(cloud, getClouds()));
+ }
+ }
+ };
+
+ private Job viewerInputJob = new Job("") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+
+ return Status.OK_STATUS;
+ }
+ };
+
+ public AbstractCloudElementTableView() {
+ lastSelectedCloudPref = new TextPreferenceValue(getSelectedCloudPrefsKey(), Activator.getDefault());
+ }
+
+ private class ColumnListener extends SelectionAdapter {
+
+ private int column;
+
+ public ColumnListener(int column) {
+ this.column = column;
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ TableViewerColumnComparator comparator = (TableViewerColumnComparator) viewer.getComparator();
+ Table t = viewer.getTable();
+ if (comparator.getColumn() == column) {
+ comparator.reverseDirection();
+ }
+ comparator.setColumn(column);
+ TableColumn tc = (TableColumn) e.getSource();
+ t.setSortColumn(tc);
+ t.setSortDirection(SWT.NONE);
+ viewer.refresh();
+ }
+ };
+
+ protected abstract String getSelectedCloudPrefsKey();
+
+ protected abstract void addListener(DeltaCloud cloud);
+
+ protected abstract void removeListener(DeltaCloud cloud);
+
+ @Override
+ public void dispose() {
+ for (DeltaCloud cloud : getClouds()) {
+ removeListener(cloud);
+ }
+ DeltaCloudManager.getDefault().removeCloudManagerListener(this);
+ super.dispose();
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ FormLayout layout = new FormLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ container.setLayout(layout);
+
+ DeltaCloud[] clouds = getClouds();
+
+ createCloudSelector(container);
+ initCloudSelector(lastSelectedCloudPref.get(), currentCloudSelector, clouds);
+
+ Label filterLabel = new Label(container, SWT.NULL);
+ filterLabel.setText(CVMessages.getString(FILTERED_LABEL));
+ filterLabel.setToolTipText(CVMessages.getString(FILTERED_TOOLTIP));
+
+ Composite tableArea = new Composite(container, SWT.NULL);
+ viewer = createTableViewer(tableArea);
+
+ currentCloud = getCurrentCloud(currentCloudSelector.getSelectionIndex(), clouds);
+
+ addListener(currentCloud);
+ setViewerInput(currentCloud);
+ setFilterLabelVisible(currentCloud, filterLabel);
+
+ Point p1 = currentCloudSelectorLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ Point p2 = currentCloudSelector.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ int centering = (p2.y - p1.y + 1) / 2;
+
+ FormData f = new FormData();
+ f.top = new FormAttachment(0, 5 + centering);
+ f.left = new FormAttachment(0, 30);
+ currentCloudSelectorLabel.setLayoutData(f);
+
+ f = new FormData();
+ f.top = new FormAttachment(0, 5);
+ f.left = new FormAttachment(currentCloudSelectorLabel, 5);
+ currentCloudSelector.setLayoutData(f);
+
+ f = new FormData();
+ f.top = new FormAttachment(0, 5 + centering);
+ f.right = new FormAttachment(100, -10);
+ filterLabel.setLayoutData(f);
+
+ f = new FormData();
+ f.top = new FormAttachment(currentCloudSelector, 8);
+ f.left = new FormAttachment(0, 0);
+ f.right = new FormAttachment(100, 0);
+ f.bottom = new FormAttachment(100, 0);
+ tableArea.setLayoutData(f);
+
+ // Create the help context id for the viewer's control
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.jboss.tools.deltacloud.ui.viewer");
+ hookContextMenu(viewer.getControl());
+ getSite().setSelectionProvider(viewer);
+ getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(workbenchSelectionListener);
+
+ DeltaCloudManager.getDefault().addCloudManagerListener(this);
+ }
+
+ private TableViewer createTableViewer(Composite tableArea) {
+ TableColumnLayout tableLayout = new TableColumnLayout();
+ tableArea.setLayout(tableLayout);
+
+ TableViewer viewer = new TableViewer(tableArea,
+ SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI);
+ Table table = viewer.getTable();
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ ITableContentAndLabelProvider provider = getContentAndLabelProvider();
+ viewer.setContentProvider(provider);
+ viewer.setLabelProvider(provider);
+ createColumns(tableLayout, table);
+
+ viewer.setComparator(new TableViewerColumnComparator());
+ table.setSortDirection(SWT.NONE);
+
+ return viewer;
+ }
+
+ protected abstract ITableContentAndLabelProvider getContentAndLabelProvider();
+
+ private void setViewerInput(DeltaCloud cloud) {
+ if (currentCloud != null) {
+ viewer.setInput(currentCloud);
+ }
+ }
+
+ /**
+ * Gets the clouds that are available in the model.
+ *
+ * @return the clouds
+ */
+ private DeltaCloud[] getClouds() {
+ DeltaCloud[] clouds = new DeltaCloud[] {};
+ try {
+ clouds = DeltaCloudManager.getDefault().getClouds();
+ } catch (DeltaCloudException e) {
+ // TODO: internationalize strings
+ ErrorUtils.handleError(
+ "Error",
+ "Could not get all clouds",
+ e, Display.getDefault().getActiveShell());
+ }
+ return clouds;
+ }
+
+ private int getCloudIndex(DeltaCloud cloud, DeltaCloud[] clouds) {
+ if (cloud == null) {
+ return 0;
+ }
+ return getCloudIndex(cloud.getName(), clouds);
+ }
+
+ private int getCloudIndex(String cloudName, DeltaCloud[] clouds) {
+ int index = 0;
+ if (cloudName != null && clouds.length > 0) {
+ for (int i = 0; i < clouds.length; i++) {
+ DeltaCloud cloud = clouds[i];
+ if (cloudName != null && cloudName.equals(cloud.getName())) {
+ index = i;
+ break;
+ }
+ }
+ }
+ return index;
+ }
+
+ private void setFilterLabelVisible(DeltaCloud currentCloud, Label filterLabel) {
+ if (currentCloud == null) {
+ filterLabel.setVisible(false);
+ return;
+ }
+
+ IInstanceFilter filter = currentCloud.getInstanceFilter();
+ filterLabel.setVisible(!filter.toString().equals(IInstanceFilter.ALL_STRING));
+ }
+
+ private DeltaCloud getCurrentCloud(int cloudIndex, DeltaCloud[] clouds) {
+ if (cloudIndex < 0 || cloudIndex >= clouds.length) {
+ return null;
+ }
+
+ return clouds[cloudIndex];
+ }
+
+ private void createColumns(TableColumnLayout tableLayout, Table table) {
+ for (int i = 0; i < InstanceViewLabelAndContentProvider.Column.getSize(); ++i) {
+ InstanceViewLabelAndContentProvider.Column c =
+ InstanceViewLabelAndContentProvider.Column.getColumn(i);
+ TableColumn tc = new TableColumn(table, SWT.NONE);
+ if (i == 0) {
+ table.setSortColumn(tc);
+ }
+ tc.setText(CVMessages.getString(c.name()));
+ tableLayout.setColumnData(tc, new ColumnWeightData(c.getWeight(), true));
+ tc.addSelectionListener(new ColumnListener(i));
+ }
+ }
+
+ private void createCloudSelector(Composite parent) {
+ this.currentCloudSelectorLabel = new Label(parent, SWT.NULL);
+ currentCloudSelectorLabel.setText(CVMessages.getString(CLOUD_SELECTOR_LABEL));
+
+ this.currentCloudSelector = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
+ currentCloudSelector.addModifyListener(cloudModifyListener);
+ // Following is a kludge so that on Linux the Combo is read-only but
+ // has a white background.
+ currentCloudSelector.addVerifyListener(new VerifyListener() {
+ @Override
+ public void verifyText(VerifyEvent e) {
+ e.doit = false;
+ }
+ });
+ }
+
+ private void hookContextMenu(Control control) {
+ IMenuManager contextMenu = UIUtils.createContextMenu(control);
+ UIUtils.registerContributionManager(UIUtils.getContextMenuId(getViewID()), contextMenu, control);
+ }
+
+ protected abstract String getViewID();
+
+ private void initCloudSelector(String cloudNameToSelect, Combo cloudSelector, DeltaCloud[] clouds) {
+ if (clouds.length > 0
+ && cloudNameToSelect != null && cloudNameToSelect.length() > 0) {
+ cloudSelector.setItems(toCloudNames(clouds));
+ cloudSelector.select(getCloudIndex(cloudNameToSelect, clouds));
+ }
+ }
+
+ public void cloudsChanged(int type) {
+ int currIndex = 0;
+ if (currentCloud != null) {
+ currIndex = currentCloudSelector.getSelectionIndex();
+ }
+ DeltaCloud[] clouds = getClouds();
+ int index = getCloudIndex(currentCloud, getClouds());
+ if (type == ICloudManagerListener.RENAME_EVENT) {
+ index = currIndex; // no change in cloud displayed
+ }
+
+ String[] cloudNames = toCloudNames(clouds);
+ setCloudSelectorItems(cloudNames);
+ this.currentCloud = getCurrentCloud(index, clouds);
+
+ if (cloudNames.length > 0) {
+ currentCloudSelector.setText(cloudNames[index]);
+ setViewerInput(currentCloud);
+ } else {
+ currentCloudSelector.setText("");
+ setViewerInput(null);
+ }
+ }
+
+ private String[] toCloudNames(DeltaCloud[] clouds) {
+ List<String> cloudNames = new ArrayList<String>();
+ for (DeltaCloud cloud : clouds) {
+ if (cloud != null) {
+ cloudNames.add(cloud.getName());
+ }
+ }
+ return (String[]) cloudNames.toArray(new String[cloudNames.size()]);
+ }
+
+ private void setCloudSelectorItems(String[] cloudNames) {
+ currentCloudSelector.removeModifyListener(cloudModifyListener);
+ currentCloudSelector.setItems(cloudNames);
+ currentCloudSelector.addModifyListener(cloudModifyListener);
+ }
+
+ /**
+ * Refresh the states of the commands in the toolbar.
+ */
+ protected abstract void refreshToolbarCommandStates();
+
+ public void listChanged(final DeltaCloud cloud, final CLOUDELEMENT[] cloudChildren) {
+ // Run following under Display thread since this can be
+ // triggered by a non-display thread notifying listeners.
+ if (cloud != null
+ && currentCloud != null
+ && cloud.getName().equals(currentCloud.getName())) {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ // does not add identical instance twice
+ addListener(cloud);
+ setViewerInput(cloud);
+ refreshToolbarCommandStates();
+ }
+ });
+ }
+ }
+
+ @Override
+ public void setFocus() {
+ viewer.getControl().setFocus();
+ }
+
+}
Property changes on: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-12-03 19:07:50 UTC (rev 27164)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-12-03 19:11:47 UTC (rev 27165)
@@ -16,10 +16,14 @@
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
/**
+ * A view that displays images of a DeltaCloud.
+ *
+ * @see DeltaCloud#getImages()
+ *
* @author Jeff Johnston
* @author Andre Dietisheim
*/
-public class ImageView extends AbstractCloudChildrenTableView<DeltaCloudImage> implements IImageListListener {
+public class ImageView extends AbstractCloudElementTableView<DeltaCloudImage> implements IImageListListener {
@Override
protected String getSelectedCloudPrefsKey() {
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-12-03 19:07:50 UTC (rev 27164)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-12-03 19:11:47 UTC (rev 27165)
@@ -18,10 +18,14 @@
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
/**
+ * A view that displays instances of a DeltaCloud
+ *
+ * @see DeltaCloud#getInstances()
+ *
* @author Jeff Johnston
* @author Andre Dietisheim
*/
-public class InstanceView extends AbstractCloudChildrenTableView<DeltaCloudInstance> implements IInstanceListListener {
+public class InstanceView extends AbstractCloudElementTableView<DeltaCloudInstance> implements IInstanceListListener {
protected String getSelectedCloudPrefsKey() {
return IDeltaCloudPreferenceConstants.LAST_CLOUD_INSTANCE_VIEW;
14 years
JBoss Tools SVN: r27164 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 14:07:50 -0500 (Fri, 03 Dec 2010)
New Revision: 27164
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java
Log:
[JBIDE-7688] provide common superclass for ImageViewContentAndLabelProvider and InstanceViewContentAndLabelProvider
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-03 19:07:22 UTC (rev 27163)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-03 19:07:50 UTC (rev 27164)
@@ -38,7 +38,7 @@
private DeltaCloud cloud;
private Collection<CLOUDELEMENT> cloudElements;
private ICloudElementFilter<CLOUDELEMENT> localFilter;
-
+
@Override
public Object[] getElements(Object inputElement) {
if (cloudElements == null) {
@@ -50,7 +50,7 @@
public void setFilter(ICloudElementFilter<CLOUDELEMENT> filter) {
this.localFilter = filter;
}
-
+
@Override
public void dispose() {
this.cloud = null;
@@ -79,10 +79,10 @@
if (cloud == null) {
return null;
}
-
+
ICloudElementFilter<CLOUDELEMENT> filter = null;
filter = getCloudFilter(cloud);
-
+
if (filter == null) {
return Arrays.asList(getCloudElements(cloud));
}
14 years
JBoss Tools SVN: r27163 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 14:07:22 -0500 (Fri, 03 Dec 2010)
New Revision: 27163
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java
Log:
[JBIDE-7688] provide common superclass for ImageViewContentAndLabelProvider and InstanceViewContentAndLabelProvider
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-03 19:03:45 UTC (rev 27162)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-03 19:07:22 UTC (rev 27163)
@@ -26,7 +26,11 @@
import org.jboss.tools.deltacloud.ui.ErrorUtils;
/**
- * @author André Dietisheim
+ * A common superclass for content- and label-providers that operate on
+ * IDeltaCloudElements (currently DeltaCloudImage and DeltaCloudInstance)
+ *
+ * @author Jeff Johnston
+ * @author Andre Dietisheim
*/
public abstract class AbstractCloudElementViewLabelAndContentProvider<CLOUDELEMENT extends IDeltaCloudElement> extends
BaseLabelProvider implements ITableContentAndLabelProvider {
14 years
JBoss Tools SVN: r27162 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 14:03:45 -0500 (Fri, 03 Dec 2010)
New Revision: 27162
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
Log:
[JBIDE-7688] provide common superclass for ImageViewContentAndLabelProvider and InstanceViewContentAndLabelProvider
Added: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java (rev 0)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-03 19:03:45 UTC (rev 27162)
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are 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 Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.ui.views;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.viewers.BaseLabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Display;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
+import org.jboss.tools.deltacloud.core.DeltaCloudImage;
+import org.jboss.tools.deltacloud.core.ICloudElementFilter;
+import org.jboss.tools.deltacloud.core.IDeltaCloudElement;
+import org.jboss.tools.deltacloud.ui.ErrorUtils;
+
+/**
+ * @author André Dietisheim
+ */
+public abstract class AbstractCloudElementViewLabelAndContentProvider<CLOUDELEMENT extends IDeltaCloudElement> extends
+ BaseLabelProvider implements ITableContentAndLabelProvider {
+
+ private DeltaCloud cloud;
+ private Collection<CLOUDELEMENT> cloudElements;
+ private ICloudElementFilter<CLOUDELEMENT> localFilter;
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ if (cloudElements == null) {
+ return new DeltaCloudImage[] {};
+ }
+ return cloudElements.toArray();
+ }
+
+ public void setFilter(ICloudElementFilter<CLOUDELEMENT> filter) {
+ this.localFilter = filter;
+ }
+
+ @Override
+ public void dispose() {
+ this.cloud = null;
+ this.cloudElements = null;
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput != null) {
+ try {
+ Assert.isLegal(newInput instanceof DeltaCloud);
+ this.cloud = (DeltaCloud) newInput;
+ this.cloudElements = filter(cloud);
+ } catch (DeltaCloudException e) {
+ this.cloudElements = Collections.emptyList();
+ // TODO: internationalize strings
+ ErrorUtils.handleError(
+ "Error",
+ "Could not display elements for cloud " + cloud.getName(),
+ e, Display.getDefault().getActiveShell());
+ }
+ }
+ }
+
+ protected Collection<CLOUDELEMENT> filter(DeltaCloud cloud) throws DeltaCloudException {
+ if (cloud == null) {
+ return null;
+ }
+
+ ICloudElementFilter<CLOUDELEMENT> filter = null;
+ filter = getCloudFilter(cloud);
+
+ if (filter == null) {
+ return Arrays.asList(getCloudElements(cloud));
+ }
+
+ return filter.filter(getCloudElements(cloud));
+ }
+
+ private ICloudElementFilter<CLOUDELEMENT> getFilter(DeltaCloud cloud) {
+ if (localFilter != null) {
+ return localFilter;
+ } else {
+ return getFilter(cloud);
+ }
+ }
+
+ protected abstract ICloudElementFilter<CLOUDELEMENT> getCloudFilter(DeltaCloud cloud);
+
+ protected abstract CLOUDELEMENT[] getCloudElements(DeltaCloud cloud) throws DeltaCloudException;
+}
Property changes on: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java 2010-12-03 18:59:05 UTC (rev 27161)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java 2010-12-03 19:03:45 UTC (rev 27162)
@@ -10,30 +10,22 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
-import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.jface.viewers.BaseLabelProvider;
-import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudImage;
-import org.jboss.tools.deltacloud.core.IImageFilter;
-import org.jboss.tools.deltacloud.ui.ErrorUtils;
+import org.jboss.tools.deltacloud.core.ICloudElementFilter;
/**
* @author Jeff Johnston
* @author André Dietisheim
*/
-public class ImageViewLabelAndContentProvider extends BaseLabelProvider implements ITableContentAndLabelProvider {
+public class ImageViewLabelAndContentProvider extends AbstractCloudElementViewLabelAndContentProvider<DeltaCloudImage> implements ITableContentAndLabelProvider {
- private DeltaCloud cloud;
- private IImageFilter localFilter;
- private DeltaCloudImage[] images = new DeltaCloudImage[] {};
-
public enum Column {
NAME(0, 20),
ID(1, 20),
@@ -73,69 +65,6 @@
};
@Override
- public Object[] getElements(Object inputElement) {
- if (images == null) {
- return new DeltaCloudImage[] {};
- }
- return images;
- }
-
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if (newInput != null) {
- if (newInput instanceof DeltaCloud) {
- this.cloud = (DeltaCloud) newInput;
- }
- this.images = filter(cloud, getImages(newInput));
- }
- }
-
- private DeltaCloudImage[] getImages(Object newInput) {
- DeltaCloudImage[] images = new DeltaCloudImage[] {};
- if (newInput instanceof DeltaCloudImage[]) {
- images = ((DeltaCloudImage[]) newInput);
- } else if (newInput instanceof DeltaCloud) {
- cloud = (DeltaCloud) newInput;
- try {
- return cloud.getImages();
- } catch (Exception e) {
- ErrorUtils.handleError(
- "Error",
- "Could not display images for cloud " + cloud.getName(),
- e, Display.getDefault().getActiveShell());
- }
-
- }
- return images;
- }
-
- // Allow override of filter for Finding Images
- public void setFilter(IImageFilter filter) {
- this.localFilter = filter;
- }
-
- private DeltaCloudImage[] filter(DeltaCloud cloud, DeltaCloudImage[] input) {
- ArrayList<DeltaCloudImage> array = new ArrayList<DeltaCloudImage>();
- IImageFilter f = localFilter;
- if (localFilter == null && cloud != null) {
- f = cloud.getImageFilter();
- }
- for (int i = 0; i < input.length; ++i) {
- DeltaCloudImage image = input[i];
- if (f != null && f.isVisible(image)) {
- array.add(image);
- }
- }
- return array.toArray(new DeltaCloudImage[array.size()]);
- }
-
- @Override
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
@@ -157,4 +86,13 @@
return "";
}
+ protected ICloudElementFilter<DeltaCloudImage> getCloudFilter(DeltaCloud cloud) {
+ return cloud.getImageFilter();
+ }
+
+ @Override
+ protected DeltaCloudImage[] getCloudElements(DeltaCloud cloud) throws DeltaCloudException {
+ return cloud.getImages();
+ }
+
}
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java 2010-12-03 18:59:05 UTC (rev 27161)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java 2010-12-03 19:03:45 UTC (rev 27162)
@@ -10,32 +10,26 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
-import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.jface.viewers.BaseLabelProvider;
-import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
-import org.jboss.tools.deltacloud.core.IInstanceFilter;
-import org.jboss.tools.deltacloud.ui.ErrorUtils;
+import org.jboss.tools.deltacloud.core.ICloudElementFilter;
import org.jboss.tools.deltacloud.ui.SWTImagesFactory;
/**
* @author Jeff Jonhston
* @author Andre Dietisheim
*/
-public class InstanceViewLabelAndContentProvider extends BaseLabelProvider implements ITableContentAndLabelProvider {
+public class InstanceViewLabelAndContentProvider extends
+ AbstractCloudElementViewLabelAndContentProvider<DeltaCloudInstance> implements ITableContentAndLabelProvider {
- private DeltaCloud cloud;
- private DeltaCloudInstance[] instances = new DeltaCloudInstance[]{};
-
public enum Column {
NAME(0, 20),
ID(1, 20),
@@ -75,40 +69,6 @@
};
@Override
- public Object[] getElements(Object inputElement) {
- return instances;
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if (newInput != null) {
- if (newInput instanceof DeltaCloudInstance[]) {
- instances = filter((DeltaCloudInstance[]) newInput);
- } else if (newInput instanceof DeltaCloud) {
- cloud = (DeltaCloud) newInput;
- try {
- instances = filter(cloud.getInstances());
- } catch (Exception e) {
- // TODO internationalize strings
- ErrorUtils.handleError("Error", "Could not display instances for cloud " + cloud.getName(),
- e, Display.getDefault().getActiveShell());
- }
- }
- }
- }
-
- private DeltaCloudInstance[] filter(DeltaCloudInstance[] input) {
- ArrayList<DeltaCloudInstance> array = new ArrayList<DeltaCloudInstance>();
- IInstanceFilter f = cloud.getInstanceFilter();
- for (int i = 0; i < input.length; ++i) {
- DeltaCloudInstance instance = input[i];
- if (f.isVisible(instance))
- array.add(instance);
- }
- return array.toArray(new DeltaCloudInstance[array.size()]);
- }
-
- @Override
public Image getColumnImage(Object element, int columnIndex) {
Column c = Column.getColumn(columnIndex);
DeltaCloudInstance i = (DeltaCloudInstance) element;
@@ -156,4 +116,13 @@
public void dispose() {
}
+ protected ICloudElementFilter<DeltaCloudInstance> getCloudFilter(DeltaCloud cloud) {
+ return cloud.getInstanceFilter();
+ }
+
+ @Override
+ protected DeltaCloudInstance[] getCloudElements(DeltaCloud cloud) throws DeltaCloudException {
+ return cloud.getInstances();
+ }
+
}
14 years
JBoss Tools SVN: r27161 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 13:59:05 -0500 (Fri, 03 Dec 2010)
New Revision: 27161
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
Log:
[JBIDE-7688]
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-03 18:57:35 UTC (rev 27160)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-03 18:59:05 UTC (rev 27161)
@@ -1,3 +1,17 @@
+2010-12-03 André Dietisheim <adietish(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/AllImageFilter.java:
+ * src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java:
+ * src/org/jboss/tools/deltacloud/core/ImageFilter.java:
+ * src/org/jboss/tools/deltacloud/core/InstanceFilter.java:
+ * src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java:
+ [JBIDE-7688] provide common superclass and interface to ImageFilter and InstanceFilter
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java:
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudImage.java:
+ * src/org/jboss/tools/deltacloud/core/AbstractDeltaCloudElement.java:
+ * src/org/jboss/tools/deltacloud/core/IDeltaCloudElement.java:
+ [JBIDE-7688] provide common superclass and interface to DeltaCloudImage and DeltaCloudInstance
+
2010-11-26 André Dietisheim <adietish(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/SecurePasswordStore.java:
14 years
JBoss Tools SVN: r27160 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 13:57:35 -0500 (Fri, 03 Dec 2010)
New Revision: 27160
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java
Log:
[JBIDE-7688] provide common superclass and interface to ImageFilter and InstanceFilter
Added: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java (rev 0)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java 2010-12-03 18:57:35 UTC (rev 27160)
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.deltacloud.core;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.core.runtime.Assert;
+
+/**
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
+public abstract class AbstractCloudElementFilter<CLOUDELEMENT extends IDeltaCloudElement> implements
+ ICloudElementFilter<CLOUDELEMENT> {
+
+ private IFieldMatcher nameRule;
+ private IFieldMatcher idRule;
+
+ public Collection<CLOUDELEMENT> filter(CLOUDELEMENT[] cloudElements) {
+ List<CLOUDELEMENT> filteredElements = new ArrayList<CLOUDELEMENT>();
+ for (CLOUDELEMENT cloudElement : cloudElements) {
+ if (matches(cloudElement)) {
+ filteredElements.add(cloudElement);
+ }
+ }
+ return filteredElements;
+ }
+
+ protected boolean matches(CLOUDELEMENT cloudElement) {
+ return nameRule.matches(cloudElement.getName())
+ && idRule.matches(cloudElement.getId());
+ }
+
+ public abstract void setRules(String rulesString) throws PatternSyntaxException;
+
+ protected Iterator<String> setRules(String ruleString, Iterator<String> rulesIterator)
+ throws PatternSyntaxException {
+ this.nameRule = createRule(rulesIterator);
+ this.idRule = createRule(rulesIterator);
+ return rulesIterator;
+ }
+
+ protected Iterator<String> getRulesIterator(String ruleString) {
+ return Arrays.asList(ruleString.split(";")).iterator();
+ }
+
+ protected IFieldMatcher createRule(Iterator<String> rulesIterator) {
+ Assert.isLegal(rulesIterator.hasNext());
+ String expression = rulesIterator.next();
+ if (expression.equals(ALL_MATCHER_EXPRESSION)) { //$NON-NLS-1$
+ return new AllFieldMatcher();
+ } else {
+ return new FieldMatcher(expression);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return nameRule + ";" //$NON-NLS-1$
+ + idRule + ";"; //$NON-NLS-1$
+ }
+
+ @Override
+ public IFieldMatcher getNameRule() {
+ return nameRule;
+ }
+
+ @Override
+ public IFieldMatcher getIdRule() {
+ return idRule;
+ }
+}
Property changes on: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java 2010-12-03 18:47:10 UTC (rev 27159)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java 2010-12-03 18:57:35 UTC (rev 27160)
@@ -10,12 +10,21 @@
******************************************************************************/
package org.jboss.tools.deltacloud.core;
-public class AllImageFilter implements IImageFilter {
+/**
+ * A filter for images that matches on all elements (no criteria checked)
+ *
+ * @see IImageFilter
+ * @see DeltaCloud#getImageFilter()
+ *
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
+public class AllImageFilter extends AbstractCloudElementFilter<DeltaCloudImage> implements IImageFilter {
private IFieldMatcher matcher = new AllFieldMatcher();
@Override
- public boolean isVisible(DeltaCloudImage image) {
+ public boolean matches(DeltaCloudImage image) {
return true;
}
@@ -28,15 +37,7 @@
public String toString() {
return ALL_STRING;
}
-
- public IFieldMatcher getNameRule() {
- return matcher;
- }
-
- public IFieldMatcher getIdRule() {
- return matcher;
- }
-
+
public IFieldMatcher getArchRule() {
return matcher;
}
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java 2010-12-03 18:47:10 UTC (rev 27159)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java 2010-12-03 18:57:35 UTC (rev 27160)
@@ -1,11 +1,20 @@
package org.jboss.tools.deltacloud.core;
-public class AllInstanceFilter implements IInstanceFilter {
+/**
+ * A filter for instances that matches on all elements (no criteria checked)
+ *
+ * @see IInstanceFilter
+ * @see DeltaCloud#getInstanceFilter()
+ *
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
+public class AllInstanceFilter extends AbstractCloudElementFilter<DeltaCloudInstance> implements IInstanceFilter {
private IFieldMatcher matcher = new AllFieldMatcher();
-
+
@Override
- public boolean isVisible(DeltaCloudInstance instance) {
+ public boolean matches(DeltaCloudInstance instance) {
return true;
}
@@ -13,23 +22,13 @@
public void setRules(String ruleString) {
// ignore, never set the rules for this filter
}
-
+
@Override
public String toString() {
return ALL_STRING;
}
-
+
@Override
- public IFieldMatcher getNameRule() {
- return matcher; //$NON-NLS-1$
- }
-
- @Override
- public IFieldMatcher getIdRule() {
- return matcher; //$NON-NLS-1$
- }
-
- @Override
public IFieldMatcher getImageIdRule() {
return matcher;
}
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java 2010-12-03 18:47:10 UTC (rev 27159)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java 2010-12-03 18:57:35 UTC (rev 27160)
@@ -10,27 +10,38 @@
******************************************************************************/
package org.jboss.tools.deltacloud.core;
+import java.util.Collection;
+
+
/**
+ * A filter interface that may be applied on IDeltaCloudElement. Known implementors are IImageFilter and IInstanceFilter
+ *
+ * @see IDeltaCloudElement
+ * @see IImageFilter
+ * @see IInstanceFilter
+ *
* @author Jeff Johnston
* @author André Dietisheim
*/
-public interface ICloudElementFilter<CLOUDCHILD> {
+public interface ICloudElementFilter<CLOUDELEMENT extends IDeltaCloudElement> {
public static final String EXPRESSION_DELIMITER = ";"; // $NON-NLS-1$
public static final String ALL_MATCHER_EXPRESSION = "*"; //$NON-NLS-1$
- public static final String ALL_STRING =
- ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // name
- + ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // id
- + ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // arch
- + ALL_MATCHER_EXPRESSION; // desc
+ public static final String ALL_STRING =
+ ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // name
+ + ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // id
+ + ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // arch
+ + ALL_MATCHER_EXPRESSION; // desc
- public boolean isVisible(CLOUDCHILD cloudChild);
+ public Collection<CLOUDELEMENT> filter(CLOUDELEMENT[] cloudElements);
+
+// public boolean matches(CLOUDELEMENT cloudElement);
+
public void setRules(String ruleString);
+
public IFieldMatcher getNameRule();
+
public IFieldMatcher getIdRule();
-
-
-
}
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java 2010-12-03 18:47:10 UTC (rev 27159)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java 2010-12-03 18:57:35 UTC (rev 27160)
@@ -10,19 +10,25 @@
******************************************************************************/
package org.jboss.tools.deltacloud.core;
+import java.util.Iterator;
import java.util.regex.PatternSyntaxException;
-public class ImageFilter implements IImageFilter {
+/**
+ * A filter that may be applied on DeltaCloudImages
+ *
+ * @see DeltaCloudImage
+ *
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
+public class ImageFilter extends AbstractCloudElementFilter<DeltaCloudImage> implements IImageFilter {
- private IFieldMatcher nameRule;
- private IFieldMatcher idRule;
private IFieldMatcher archRule;
private IFieldMatcher descRule;
@Override
- public boolean isVisible(DeltaCloudImage image) {
- return nameRule.matches(image.getName()) &&
- idRule.matches(image.getId()) &&
+ public boolean matches(DeltaCloudImage image) {
+ return super.matches(image) &&
archRule.matches(image.getArchitecture()) &&
descRule.matches(image.getDescription());
}
@@ -30,37 +36,18 @@
@Override
public void setRules(String ruleString) throws PatternSyntaxException {
// TODO: replace filter passing (;-delimited string) by list
- String[] tokens = ruleString.split(";");
- this.nameRule = createRule(tokens[0]);
- this.idRule = createRule(tokens[1]);
- this.archRule = createRule(tokens[2]);
- this.descRule = createRule(tokens[3]);
+ Iterator<String> rulesIterator = super.setRules(ruleString, getRulesIterator(ruleString));
+ this.archRule = createRule(rulesIterator);
+ this.descRule = createRule(rulesIterator);
}
-
- private IFieldMatcher createRule(String token) {
- if (token.equals(ALL_MATCHER_EXPRESSION)) { //$NON-NLS-1$
- return new AllFieldMatcher();
- } else {
- return new FieldMatcher(token);
- }
- }
@Override
public String toString() {
- return nameRule + ";" //$NON-NLS-1$
- + idRule + ";" //$NON-NLS-1$
+ return super.toString() //$NON-NLS-1$
+ archRule + ";" //$NON-NLS-1$
+ descRule; //$NON-NLS-1$
}
-
- public IFieldMatcher getNameRule() {
- return nameRule;
- }
- public IFieldMatcher getIdRule() {
- return idRule;
- }
-
public IFieldMatcher getArchRule() {
return archRule;
}
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java 2010-12-03 18:47:10 UTC (rev 27159)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java 2010-12-03 18:57:35 UTC (rev 27160)
@@ -10,15 +10,19 @@
******************************************************************************/
package org.jboss.tools.deltacloud.core;
+import java.util.Iterator;
import java.util.regex.PatternSyntaxException;
/**
+ * A filter that may be applied on DeltaCloudInstances
+ *
+ * @see DeltaCloudInstance
+ *
* @author Jeff Johnston
+ * @author André Dietisheim
*/
-public class InstanceFilter implements IInstanceFilter {
+public class InstanceFilter extends AbstractCloudElementFilter<DeltaCloudInstance> implements IInstanceFilter {
- private IFieldMatcher nameRule;
- private IFieldMatcher idRule;
private IFieldMatcher imageIdRule;
private IFieldMatcher realmRule;
private IFieldMatcher profileRule;
@@ -26,9 +30,8 @@
private IFieldMatcher keyNameRule;
@Override
- public boolean isVisible(DeltaCloudInstance instance) {
- return nameRule.matches(instance.getName()) &&
- idRule.matches(instance.getId()) &&
+ public boolean matches(DeltaCloudInstance instance) {
+ return super.matches(instance) &&
imageIdRule.matches(instance.getImageId()) &&
ownerIdRule.matches(instance.getOwnerId()) &&
keyNameRule.matches(instance.getKey()) &&
@@ -38,28 +41,17 @@
@Override
public void setRules(String ruleString) throws PatternSyntaxException {
- String[] tokens = ruleString.split(";");
- this.nameRule = createRule(tokens[0]);
- this.idRule = createRule(tokens[1]);
- this.imageIdRule = createRule(tokens[2]);
- this.ownerIdRule = createRule(tokens[3]);
- this.keyNameRule = createRule(tokens[4]);
- this.realmRule = createRule(tokens[5]);
- this.profileRule = createRule(tokens[6]);
+ Iterator<String> rulesIterator = super.setRules(ruleString, getRulesIterator(ruleString));
+ this.imageIdRule = createRule(rulesIterator);
+ this.ownerIdRule = createRule(rulesIterator);
+ this.keyNameRule = createRule(rulesIterator);
+ this.realmRule = createRule(rulesIterator);
+ this.profileRule = createRule(rulesIterator);
}
-
- private IFieldMatcher createRule(String expression) {
- if (expression.equals(ALL_MATCHER_EXPRESSION)) { //$NON-NLS-1$
- return new AllFieldMatcher();
- } else {
- return new FieldMatcher(expression);
- }
- }
@Override
public String toString() {
- return nameRule + ";" //$NON-NLS-1$
- + idRule + ";" //$NON-NLS-1$
+ return super.toString()
+ imageIdRule + ";" //$NON-NLS-1$
+ ownerIdRule + ";" //$NON-NLS-1$
+ keyNameRule + ";" //$NON-NLS-1$
@@ -68,16 +60,6 @@
}
@Override
- public IFieldMatcher getNameRule() {
- return nameRule;
- }
-
- @Override
- public IFieldMatcher getIdRule() {
- return idRule;
- }
-
- @Override
public IFieldMatcher getImageIdRule() {
return imageIdRule;
}
14 years
JBoss Tools SVN: r27159 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 13:47:10 -0500 (Fri, 03 Dec 2010)
New Revision: 27159
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/FilterInstancesHandler.java
Log:
[JBIDE-7688] renamed InstanceFilter to InstanceFilterWizard since it is a wizard (and shall not be mixed up with the filter IntanceFilter)
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/FilterInstancesHandler.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/FilterInstancesHandler.java 2010-12-03 18:46:41 UTC (rev 27158)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/FilterInstancesHandler.java 2010-12-03 18:47:10 UTC (rev 27159)
@@ -24,7 +24,7 @@
import org.eclipse.ui.handlers.HandlerUtil;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
-import org.jboss.tools.internal.deltacloud.ui.wizards.InstanceFilter;
+import org.jboss.tools.internal.deltacloud.ui.wizards.InstanceFilterWizard;
/**
* @author Andre Dietisheim
@@ -48,7 +48,7 @@
@Override
public void run() {
- IWizard wizard = new InstanceFilter(cloud);
+ IWizard wizard = new InstanceFilterWizard(cloud);
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.create();
dialog.open();
14 years
JBoss Tools SVN: r27158 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-12-03 13:46:41 -0500 (Fri, 03 Dec 2010)
New Revision: 27158
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/TextPreferenceValue.java
Log:
added convenience constructor
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/TextPreferenceValue.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/TextPreferenceValue.java 2010-12-03 18:46:15 UTC (rev 27157)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/preferences/TextPreferenceValue.java 2010-12-03 18:46:41 UTC (rev 27158)
@@ -28,6 +28,10 @@
this.prefsKey = prefsKey;
}
+ public String get() {
+ return get(null);
+ }
+
public String get(String currentValue) {
if( currentValue == null || currentValue.equals("")) {
// pre-set with previously used
14 years