Control for Enumerations complete.
diff --git a/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/presentation/EnumSelector.java b/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/presentation/EnumSelector.java
index 87dc3fe..a95c45d 100644
--- a/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/presentation/EnumSelector.java
+++ b/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/presentation/EnumSelector.java
@@ -17,13 +17,19 @@
import org.eclipse.rmf.reqif10.EnumValue;
import org.eclipse.rmf.reqif10.pror.editor.agilegrid.ProrEnumerationMultiValueCellEditor;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.ShellAdapter;
+import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
@@ -32,26 +38,35 @@
import org.eclipse.ui.PlatformUI;
/**
- * This -Control represents a GUI element that allows the selection of {@link EnumValue}s.
- * It offers a save and cancel button, and is designed to be shown in a {@link Shell}.
+ * This -Control represents a GUI element that allows the selection of
+ * {@link EnumValue}s. It offers a save and cancel button, and is designed to be
+ * shown in a {@link Shell}.
*
- * It is written so that it can be used by AgileGrid (see {@link ProrEnumerationMultiValueCellEditor}
- * or stand-alone (e.g. in a search interface).
+ * It is written so that it can be used by AgileGrid (see
+ * {@link ProrEnumerationMultiValueCellEditor} or stand-alone (e.g. in a search
+ * interface).
+ *
+ * IMPORTANT: AgileGrid provides a proper shell, to be used with
+ * {@link #showEnumSelector(Shell)}. Outside AgileGrid, a Shell must be
+ * constructed BEFORE instantiating the control. You can use the static method
+ * {@link #createShell(Shell)} for this purpose.
*
* @author jastram
*/
public class EnumSelector extends Composite {
-
+
private ArrayList<EnumValue> itemList = new ArrayList<EnumValue>();
private int status = SWT.OK;
private Collection<EnumValue> originalSelection;
-
- public EnumSelector(List<EnumValue> items,
- Collection<EnumValue> selection, Composite parent, int style) {
+ /**
+ * Createes the Control.
+ */
+ public EnumSelector(List<EnumValue> items, Collection<EnumValue> selection,
+ Composite parent, int style) {
super(parent, style);
originalSelection = selection;
-
+
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
@@ -78,7 +93,8 @@
for (EnumValue enumValue : items) {
TableItem tableItem = new TableItem(table, SWT.NONE);
- String enumId = enumValue.getLongName() == null ? enumValue.getIdentifier() : enumValue.getLongName();
+ String enumId = enumValue.getLongName() == null ? enumValue
+ .getIdentifier() : enumValue.getLongName();
tableItem.setText(enumId);
tableItem.setData(enumValue);
if (selection.contains(enumValue)) {
@@ -88,10 +104,12 @@
}
Composite buttonPanel = new Composite(this, SWT.NONE);
- buttonPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ buttonPanel
+ .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
buttonPanel.setLayout(new FillLayout(SWT.HORIZONTAL));
Button cancel = new Button(buttonPanel, SWT.PUSH);
- cancel.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
+ cancel.setImage(PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_TOOL_DELETE));
cancel.addSelectionListener(new SelectionAdapter() {
@Override
@@ -100,9 +118,10 @@
Display.getCurrent().getActiveShell().close();
}
});
-
+
Button ok = new Button(buttonPanel, SWT.PUSH);
- ok.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVE_EDIT));
+ ok.setImage(PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_ETOOL_SAVE_EDIT));
ok.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -111,7 +130,11 @@
}
});
}
-
+
+ /**
+ * Opens the control. Make sure to get the shell via
+ * {@link #createShell(Control)}, unless you use this via AgileGrid.
+ */
public int showEnumSelector(Shell shell) {
shell.pack();
@@ -120,12 +143,55 @@
Display.getCurrent().sleep();
}
}
-
+
return status;
}
-
+
+ /**
+ * Returns the selected items. If the user cancelled, the original,
+ * unmodified selection will be returned.
+ */
public Collection<EnumValue> getItems() {
return status == SWT.OK ? itemList : originalSelection;
}
-
+
+ /**
+ * Creates a shell that: is positioned below the parent; can be closed via
+ * ESC; is closed if the user clicks outside, or if the shell loses focus.
+ *
+ * Unless the user cancels explicitly (button), the new values will be
+ * accepted.
+ */
+ public static Shell createShell(Control parent) {
+ final Shell shell = new Shell(parent.getShell(), SWT.RESIZE
+ | SWT.ON_TOP);
+ shell.setBackground(parent.getBackground());
+ shell.setLayout(new FillLayout());
+ shell.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (e.character == SWT.ESC) { // Escape
+ shell.close();
+ }
+ }
+ });
+
+ shell.addShellListener(new ShellAdapter() {
+ @Override
+ public void shellDeactivated(ShellEvent e) {
+ shell.close();
+ }
+ });
+
+ Display display = parent.getDisplay();
+
+ Rectangle clientRect = display.map(parent, null, new Rectangle(0, 0, 0,
+ 0));
+ shell.setBounds(clientRect.x, clientRect.y + parent.getBounds().height,
+ 0, 0);
+ shell.open();
+ shell.layout();
+ return shell;
+ }
+
}
\ No newline at end of file
diff --git a/org.eclipse.rmf.reqif10.search.ui/plugin.properties b/org.eclipse.rmf.reqif10.search.ui/plugin.properties
index b9c6bd4..62fafe9 100644
--- a/org.eclipse.rmf.reqif10.search.ui/plugin.properties
+++ b/org.eclipse.rmf.reqif10.search.ui/plugin.properties
@@ -21,3 +21,5 @@
operator_after = after
operator_contains_all = all
operator_contains_any = any
+operator_is_set = set
+operator_is_not_set = not set
diff --git a/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/filter/ui/FilterControl.java b/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/filter/ui/FilterControl.java
index a44a722..ec86af7 100644
--- a/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/filter/ui/FilterControl.java
+++ b/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/filter/ui/FilterControl.java
@@ -15,6 +15,7 @@
import org.eclipse.rmf.reqif10.AttributeDefinition;
import org.eclipse.rmf.reqif10.AttributeDefinitionBoolean;
import org.eclipse.rmf.reqif10.AttributeDefinitionDate;
+import org.eclipse.rmf.reqif10.AttributeDefinitionEnumeration;
import org.eclipse.rmf.reqif10.AttributeDefinitionInteger;
import org.eclipse.rmf.reqif10.AttributeDefinitionReal;
import org.eclipse.rmf.reqif10.AttributeDefinitionString;
@@ -22,6 +23,7 @@
import org.eclipse.rmf.reqif10.search.filter.AbstractTextFilter;
import org.eclipse.rmf.reqif10.search.filter.BoolFilter;
import org.eclipse.rmf.reqif10.search.filter.DateFilter;
+import org.eclipse.rmf.reqif10.search.filter.EnumFilter;
import org.eclipse.rmf.reqif10.search.filter.IFilter;
import org.eclipse.rmf.reqif10.search.filter.NumberFilter;
import org.eclipse.swt.widgets.Composite;
@@ -53,6 +55,7 @@
if (filter instanceof DateFilter) return new FilterControlDate(parent, (DateFilter)filter);
if (filter instanceof NumberFilter) return new FilterControlNumber(parent, (NumberFilter)filter);
if (filter instanceof BoolFilter) return new FilterControlBoolean(parent, (BoolFilter)filter);
+ if (filter instanceof EnumFilter) return new FilterControlEnum(parent, (EnumFilter)filter);
throw new IllegalArgumentException("Don't know how to create: " + filter);
}
@@ -84,6 +87,9 @@
} else if (attribute instanceof AttributeDefinitionBoolean) {
return new FilterControlBoolean(parent,
(AttributeDefinitionBoolean) attribute);
+ } else if (attribute instanceof AttributeDefinitionEnumeration) {
+ return new FilterControlEnum(parent,
+ (AttributeDefinitionEnumeration) attribute);
}
throw new IllegalArgumentException("Don't know how to create (yet): "
+ attribute);
diff --git a/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/filter/ui/FilterControlEnum.java b/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/filter/ui/FilterControlEnum.java
new file mode 100644
index 0000000..cb3a5df
--- /dev/null
+++ b/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/filter/ui/FilterControlEnum.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Formal Mind GmbH.
+ * 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:
+ * Michael Jastram - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.rmf.reqif10.search.filter.ui;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.eclipse.rmf.reqif10.AttributeDefinitionEnumeration;
+import org.eclipse.rmf.reqif10.EnumValue;
+import org.eclipse.rmf.reqif10.pror.editor.presentation.EnumSelector;
+import org.eclipse.rmf.reqif10.search.filter.EnumFilter;
+import org.eclipse.rmf.reqif10.search.filter.IFilter;
+import org.eclipse.rmf.reqif10.search.filter.IFilter.Operator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Used for plain text and XHTML
+ *
+ * @author jastram
+ */
+public class FilterControlEnum extends FilterControl {
+
+ private Button valueControl;
+ private Combo attr;
+ private AttributeDefinitionEnumeration attribute;
+ private EnumFilter templateFilter;
+ private Collection<EnumValue> items;
+
+ public FilterControlEnum(FilterPanel parent,
+ AttributeDefinitionEnumeration attribute) {
+ super(parent, SWT.FLAT);
+ this.attribute = attribute;
+ init();
+ }
+
+ public FilterControlEnum(FilterPanel parent, EnumFilter template) {
+ super(parent, SWT.FLAT);
+ this.attribute = (AttributeDefinitionEnumeration) template.getAttribute();
+ this.templateFilter = template;
+ init();
+ }
+
+ private void init() {
+ if (!(attribute instanceof AttributeDefinitionEnumeration)) {
+ throw new IllegalArgumentException("Not allowed: " + attribute);
+ }
+ setLayout(new GridLayout(2, false));
+ if (templateFilter != null) {
+ items = templateFilter.getFilterValue1();
+ } else {
+ items = new HashSet<EnumValue>();
+ }
+ createOperators();
+ createValueControl();
+ updateItems(items);
+ }
+
+ private void createValueControl() {
+ valueControl = new Button(this, SWT.PUSH | SWT.FLAT | SWT.WRAP);
+ GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ layoutData.widthHint = 200;
+ valueControl.setLayoutData(layoutData);
+ valueControl.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ popupSelector(valueControl);
+ }
+ });
+ }
+
+ protected void popupSelector(Control control) {
+ Shell shell = EnumSelector.createShell(control);
+ EnumSelector selector = new EnumSelector(attribute.getType()
+ .getSpecifiedValues(), items, shell, SWT.BORDER);
+ int status = selector.showEnumSelector(shell);
+ if (status == SWT.OK) {
+ updateItems(selector.getItems());
+ }
+ }
+
+ private void updateItems(Collection<EnumValue> items) {
+ this.items = items;
+ StringBuilder sb = new StringBuilder();
+ for (Iterator<EnumValue> i = items.iterator(); i.hasNext();) {
+ EnumValue value = i.next();
+
+ // In case items have been removed
+ if (! attribute.getType().getSpecifiedValues().contains(value)) continue;
+
+ String label = value.getLongName() != null ? value.getLongName() : value.getIdentifier();
+ sb.append(label);
+ if (i.hasNext()) sb.append(", ");
+ }
+ valueControl.setText(sb.toString());
+ getParent().layout();
+ getParent().getParent().layout();
+ }
+
+ // TODO use correct operators.
+ private void createOperators() {
+ attr = new Combo(this, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
+ GridData layoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
+ attr.setLayoutData(layoutData);
+ for (Operator operator : EnumFilter.SUPPORTED_OPERATORS) {
+ attr.add(getString(operator.toString()));
+ }
+ attr.select(0);
+ if (templateFilter != null)
+ attr.select(EnumFilter.SUPPORTED_OPERATORS.asList().indexOf(
+ templateFilter.getOperator()));
+ }
+
+ public IFilter getFilter() {
+ Operator operator = EnumFilter.SUPPORTED_OPERATORS.asList().get(attr.getSelectionIndex());
+ return new EnumFilter(operator, items, attribute);
+ }
+}
diff --git a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/EnumFilter.java b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/EnumFilter.java
index 7bea75b..9783c34 100644
--- a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/EnumFilter.java
+++ b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/EnumFilter.java
@@ -56,7 +56,9 @@
this.attributeDefinition = attributeDefinition;
this.operator = operator;
this.filterValues = new HashSet<EnumValue>(value);
- this.defaultValues = new HashSet<EnumValue>(attributeDefinition.getDefaultValue().getValues());
+ if (attributeDefinition.getDefaultValue() != null) {
+ this.defaultValues = new HashSet<EnumValue>(attributeDefinition.getDefaultValue().getValues());
+ }
}
diff --git a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/IFilter.java b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/IFilter.java
index 8dc2345..8777b3a 100644
--- a/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/IFilter.java
+++ b/org.eclipse.rmf.reqif10.search/src/org/eclipse/rmf/reqif10/search/filter/IFilter.java
@@ -43,7 +43,7 @@
CONTAINS_ALL("operator_contains_all"),
CONTAINS_ANY("operator_contains_any"),
IS_SET("operator_is_set"),
- IS_NOT_SET("operator_is_not");
+ IS_NOT_SET("operator_is_not_set");
private String label;
private Operator(String label) {