Skip to content
Snippets Groups Projects
Commit 1a01c12b authored by Simon Barner's avatar Simon Barner
Browse files

- Refactor annotation view

  - Move label provider to dedicated package
  - Move generic annotation view to dedicated package
  - Move inner classes of GenericAnnotationView to separate classes (filter support in dedicated package)
- Small documentation updates
- No functional change
refs 1841
parent 60d952fb
No related branches found
No related tags found
No related merge requests found
Showing
with 1134 additions and 28 deletions
......@@ -13,8 +13,11 @@ Bundle-Vendor: fortiss GmbH
Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.annotation,
org.fortiss.tooling.base.ui.annotation.editingsupport,
org.fortiss.tooling.base.ui.annotation.labelprovider,
org.fortiss.tooling.base.ui.annotation.valueprovider,
org.fortiss.tooling.base.ui.annotation.view,
org.fortiss.tooling.base.ui.annotation.view.generic,
org.fortiss.tooling.base.ui.annotation.view.generic.filter,
org.fortiss.tooling.base.ui.compose,
org.fortiss.tooling.base.ui.contentprovider,
org.fortiss.tooling.base.ui.databinding,
......
......@@ -13,7 +13,7 @@
<extension
point="org.eclipse.ui.views">
<view
class="org.fortiss.tooling.base.ui.annotation.view.GenericAnnotationView"
class="org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView"
icon="icons/annotation.gif"
id="org.fortiss.tooling.base.ui.annotationBase"
name="Annotation"
......
......@@ -26,10 +26,11 @@ import java.util.List;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.annotation.valueprovider.IAnnotationValueProvider;
import org.fortiss.tooling.base.ui.annotation.view.GenericAnnotationView;
import org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView;
/**
* The class {@link AnnotationEntry} is responsible for providing those annotations (or annotation
......@@ -240,7 +241,8 @@ public final class AnnotationEntry {
/**
* Creates the {@link EditingSupport} element for the {@link IAnnotatedSpecification} of type
* {@code clazz} (for use in the {@link GenericAnnotationView} .
* {@code clazz} (for use in the {@link GenericAnnotationView} or any other {@link TableViewer}
* -based view).
*
* @throws Exception
*/
......
......@@ -20,15 +20,15 @@ package org.fortiss.tooling.base.ui.annotation.editingsupport;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.view.GenericAnnotationView;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
/**
* Base class for {@link EditingSupport}s used in the {@link GenericAnnotationView}.
* Base class for {@link EditingSupport}s used in the {@link TableViewer}-based views.
*
* @author barner
* @author $Author$
......
......@@ -4,5 +4,5 @@
@ConQAT.Rating YELLOW Hash: 220FF5C80574A4AE88C30A7C56D52CE7
-->
<body>
Editing support to embed annotations into the generic table-based annotation view.
Editing support to embed annotations into the generic table-based annotation view. When a users edits the value of an annotation, the editing support replaces the label provider that has been showing the current value of the annotation and provides a widget to set a new value.
</body>
......@@ -15,10 +15,11 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view;
package org.fortiss.tooling.base.ui.annotation.labelprovider;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.wb.swt.SWTResourceManager;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
......@@ -26,10 +27,11 @@ import org.fortiss.tooling.base.model.element.IDerivedAnnotation;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.editingsupport.ComboBoxEditingSupport;
import org.fortiss.tooling.base.ui.annotation.editingsupport.ComboBoxLabelValueMapping;
import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart;
/**
* This class provides the labels in the table of the annotation view. The labels are shown when no
* item is selected for editing.
* This class provides the labels in the table of the annotation view. The labels are shown in
* {@link TableViewer}-based annotation views when no item is selected for editing.
*
* @author diewald, barner
* @author $Author$
......
......@@ -15,15 +15,16 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view;
package org.fortiss.tooling.base.ui.annotation.labelprovider;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* Provider that uses the names of {@link INamedElement}s as column labels.
* Provider that uses the comments of {@link INamedElement}s as column labels.
*
* @author barner
* @author $Author$
......
......@@ -15,10 +15,11 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view;
package org.fortiss.tooling.base.ui.annotation.labelprovider;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
......
......@@ -12,7 +12,7 @@
* Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
* Alexander Mark Diewald <diewald@fortiss.org>
*******************************************************************************/
package org.fortiss.tooling.base.ui.annotation.view;
package org.fortiss.tooling.base.ui.annotation.labelprovider;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ColumnLabelProvider;
......@@ -36,6 +36,7 @@ import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart;
/**
* A {@link ColumnLabelProvider} for annotations that displays checkboxes indicating the value of
......
......@@ -15,16 +15,18 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view;
package org.fortiss.tooling.base.ui.annotation.labelprovider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.wb.swt.SWTResourceManager;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart;
/**
* Base class for {@link ColumnLabelProvider}s. The labels are shown when no item is
* selected for editing.
* Base class for {@link ColumnLabelProvider}s. The labels are shown in {@link TableViewer}-based
* annotation views when no item is selected for editing.
*
* @author barner
* @author $Author$
......
<!--
$Id$
@version $Rev$
@ConQAT.Rating YELLOW Hash: 220FF5C80574A4AE88C30A7C56D52CE7
-->
<body>
Label providers to embed annotations into the generic table-based annotation view. Label providers are used to display the current values of annotations when they are not edited.
</body>
......@@ -26,7 +26,7 @@ import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.annotation.view.GenericAnnotationView;
import org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView;
import org.fortiss.tooling.kernel.service.base.IEObjectAware;
/**
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2014 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.generic;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
/**
* Data required to identify a column displaying a particular {@link IAnnotatedSpecification} in
* a column of the {@link GenericAnnotationView}. Used to sort columns (see
* {@link #compareTo(ColumnHandle)}).
*/
public class ColumnHandle implements Comparable<ColumnHandle> {
/**
* Character used to separate the annotation name from the instance name for multi-instance
* annotations.
*/
private final static String MULTIINSTANCE_NAME_SEPARATOR = ":";
/**
* {@link AnnotationEntry} from which a particular {@link IAnnotatedSpecification} is to be
* displayed in the column represented by this {@link ColumnHandle}.
*/
private AnnotationEntry entry;
/**
* {@link IAnnotatedSpecification} from {@code entry} to be displayed in the column
* represented by this {@link ColumnHandle}.
*/
private IAnnotatedSpecification annotatedSpecification;
/**
* Instance key identifying the particular instance of an {@link IAnnotatedSpecification} from
* {@code entry} to be displayed in the column represented by this {@link ColumnHandle} .
*/
private String instanceKey;
/** Flag if this {@link ColumnHandle} represents a {@link CreateAnnotationInstanceColumn}. */
private boolean isCreateColumn;
/** Constructs a new {@link ColumnHandle}. */
public ColumnHandle(AnnotationEntry entry, IAnnotatedSpecification annotatedSpecification,
String instanceKey, boolean isCreateColumn) {
this.entry = entry;
this.annotatedSpecification = annotatedSpecification;
this.instanceKey = instanceKey;
this.isCreateColumn = isCreateColumn;
}
/**
* Returns the {@link AnnotationEntry} from which a particular {@link IAnnotatedSpecification}
* is to be
* displayed in the column represented by this {@link ColumnHandle}.
*/
public AnnotationEntry getEntry() {
return entry;
}
/**
* Returns the {@link IAnnotatedSpecification} from {@code entry} to be displayed in the
* column represented by this {@link ColumnHandle}.
*/
public IAnnotatedSpecification getAnnotatedSpecification() {
return annotatedSpecification;
}
/**
* Returns the instance key identifying the particular instance of an
* {@link IAnnotatedSpecification} from {@code entry} to be displayed in the column
* represented by this {@link ColumnHandle} .
*/
public String getInstanceKey() {
return instanceKey;
}
/**
* Returns a flag if this {@link ColumnHandle} represents a
* {@link CreateAnnotationInstanceColumn}.
*/
public boolean isCreateColumn() {
return isCreateColumn;
}
/**
* Returns the name of a column for a given {@link IAnnotatedSpecification} represented by
* the
* given {@link ColumnHandle}.
*/
public String getColumnName() {
// Determine column name
String specName =
getEntry().getSpecificationAnnotationName(getAnnotatedSpecification().getClass());
if(getInstanceKey() != null) {
if(!specName.isEmpty()) {
specName += MULTIINSTANCE_NAME_SEPARATOR + " ";
}
specName += getInstanceKey();
} else if(specName == null || specName.isEmpty()) {
specName = "<Unnamed Annotation>";
}
return specName;
}
/** {@inheritDoc} */
@Override
public int compareTo(ColumnHandle other) {
String columnName = getColumnName();
String annotationName;
int columnNameSeparatorIndex = columnName.indexOf(MULTIINSTANCE_NAME_SEPARATOR);
if(columnNameSeparatorIndex != -1) {
annotationName = columnName.substring(0, columnNameSeparatorIndex);
} else {
annotationName = columnName;
}
String otherColumnName = other.getColumnName();
String otherAnnotationName;
int otherColumnNameSeparatorIndex = otherColumnName.indexOf(MULTIINSTANCE_NAME_SEPARATOR);
if(otherColumnNameSeparatorIndex != -1) {
otherAnnotationName = otherColumnName.substring(0, otherColumnNameSeparatorIndex);
} else {
otherAnnotationName = otherColumnName;
}
// Place "create" columns (label: "<specification name>") after their instances
// (which are labeled "<specification name>: <instance name>").
if(annotationName.equals(otherAnnotationName)) {
// Ensure uniqueness of "create" columns"
if(isCreateColumn && other.isCreateColumn) {
return 0;
}
if(isCreateColumn) {
return 1;
}
if(other.isCreateColumn) {
return -1;
}
}
// Sort alphabetically by specification column label
return columnName.compareTo(otherColumnName);
}
}
......@@ -15,7 +15,7 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view;
package org.fortiss.tooling.base.ui.annotation.view.generic;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.NotificationImpl;
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2014 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.generic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* Comparator that sorts rows according to hierarchy level. Elements within one hierarchy level
* are sorted by name.
*/
public class HierarchicalNameComparator extends ViewerComparator {
/** {@inheritDoc} */
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
if(o1 instanceof AnnotationEntry && o2 instanceof AnnotationEntry) {
IModelElement modelElement1 = ((AnnotationEntry)o1).getModelElement();
IModelElement modelElement2 = ((AnnotationEntry)o2).getModelElement();
int modelElement1Level = GenericAnnotationView.getModelElementLevel(modelElement1);
int modelElement2Level = GenericAnnotationView.getModelElementLevel(modelElement2);
EObject e1 = modelElement1;
EObject e2 = modelElement2;
if(modelElement1Level < modelElement2Level) {
// Element1 is higher than element2: Get ancestor of element2 that is at the
// level as the element1.
EObject ancestor =
GenericAnnotationView.getModelElementAncestor(modelElement2,
modelElement2Level - modelElement1Level);
if(modelElement1 == ancestor) {
// Element1 is offspring of element2
return -1;
}
// Further comparison starts on elements at the same level
e2 = ancestor;
} else if(modelElement1Level > modelElement2Level) {
// Element2 is higher than element1: Get ancestor of element1 that is at the
// level as the element2.
EObject ancestor =
GenericAnnotationView.getModelElementAncestor(modelElement1,
modelElement1Level - modelElement2Level);
if(modelElement2 == ancestor) {
// Element2 is offspring of element1
return 1;
}
// Further comparison starts on elements at the same level
e1 = ancestor;
}
// Find direct children of common root element of element1 and element2...
do {
if(e1.eContainer() == e2.eContainer()) {
break;
}
e1 = e1.eContainer();
e2 = e2.eContainer();
} while(true);
// ... and compare them by name...
if(e1 instanceof INamedElement && e2 instanceof INamedElement) {
// Elements are at the same level -> compare by name
return(((INamedElement)e1).getName().compareTo(((INamedElement)e2).getName()));
}
}
// ... or hash code (as a fallback ordering)
// int Integer.compare(int x, int y) requires JDK 1.7 which is not available
// on the build server
return new Integer(o1.hashCode()).compareTo(o2.hashCode());
}
}
......@@ -15,26 +15,29 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view;
import java.util.Collection;
package org.fortiss.tooling.base.ui.annotation.view.generic.filter;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.view.GenericAnnotationView.ColumnHandle;
import org.fortiss.tooling.base.ui.annotation.view.generic.ColumnHandle;
import org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
/**
* Row and column filter for the {@link GenericAnnotationView}. Row filtering is realized by
* inheriting {@link ViewerFilter}, whereas for column filtering is supported by
* {@link AnnotationFilter#passesColumnFilter(ColumnHandle)} that is evaluated in
* {@link GenericAnnotationView#update(Collection)}.
* Row and column filter for the {@link GenericAnnotationView}.
* <ul>
* <li>Row filtering is realized by inheriting {@link ViewerFilter} and the default filtering
* mechanism provided by {@link TableViewer}.</li>
* <li>Column filtering is supported by {@link AnnotationFilter#passesColumnFilter(ColumnHandle)}
* that is evaluated during the update of the {@link GenericAnnotationView}.</li>
* </ul>
*/
class AnnotationFilter extends ViewerFilter {
public class AnnotationFilter extends ViewerFilter {
/** Filter hint text. */
static final String FILTER_HINT_TEXT = "type filter text";
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2014 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.generic.filter;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
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.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView;
import org.fortiss.tooling.base.ui.widget.ExtendedCCombo;
/** Widget to set content filters for the {@link GenericAnnotationView}. */
public class AnnotationFilterWidget extends Composite {
/** Annotation type filter: all annotations */
private static final String ANNOTATION_TYPE_ANY = "Show all annotations";
/** Combo box Column filter option based on annotation type */
private ExtendedCCombo<Class<? extends IAnnotatedSpecification>> filterAnnotationTypeCombo;
/** Constructs a new {@link AnnotationFilterWidget} */
public AnnotationFilterWidget(Composite parent, int style, final GenericAnnotationView view) {
super(parent, style);
GridLayout layout = new GridLayout(4, false);
layout.horizontalSpacing = 50;
setLayout(layout);
// Row 1: name filter scope / labels
Composite nameFilterScopeComposite = createNameFilterScopeComposite(this, view);
nameFilterScopeComposite
.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1));
final Label modelElementTypefilterLabel = new Label(this, SWT.NULL);
modelElementTypefilterLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true,
1, 1));
modelElementTypefilterLabel.setText("Filter model element type:");
final Label hierarchyLevelFilterLabel = new Label(this, SWT.NULL);
hierarchyLevelFilterLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1,
1));
hierarchyLevelFilterLabel.setText("Filter model element hierarchy level:");
final Label annotationTypeFilterLabel = new Label(this, SWT.NULL);
annotationTypeFilterLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1,
1));
annotationTypeFilterLabel.setText("Filter annotation type:");
// Row 2: controls
Text nameFilterText = createNameFilterText(this, view);
nameFilterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1));
Button modelElementTypeFilterButton =
createModelElementTypeFilterOptionsCheckButton(this, view);
modelElementTypeFilterButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true,
1, 1));
CCombo hierarchyLevelFilterCombo = createHierarchyLevelFilterOptionsComboBox(this, view);
hierarchyLevelFilterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1,
1));
ExtendedCCombo<Class<? extends IAnnotatedSpecification>> annotationTypeFilterCombo =
createAnnotationTypeFilterOptionsComboBox(this, view);
annotationTypeFilterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1,
1));
}
/**
* Creates the {@link Text} input box for setting the pattern to filter the
* {@link GenericAnnotationView} for model element or annotation names
*/
private Text createNameFilterText(Composite parent, final GenericAnnotationView view) {
// Text input field for filter pattern
final Text nameFilterText =
new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
view.getAnnotationFilter();
nameFilterText.setText(AnnotationFilter.FILTER_HINT_TEXT);
nameFilterText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY));
// Observe changes of filter pattern
nameFilterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
String filterPattern = nameFilterText.getText();
if(filterPattern.isEmpty()) {
nameFilterText.setText(AnnotationFilter.FILTER_HINT_TEXT);
nameFilterText.selectAll();
filterPattern = AnnotationFilter.FILTER_HINT_TEXT;
}
if(filterPattern.equals(AnnotationFilter.FILTER_HINT_TEXT)) {
nameFilterText.setForeground(Display.getCurrent().getSystemColor(
SWT.COLOR_DARK_GRAY));
} else {
nameFilterText.setForeground(Display.getCurrent().getSystemColor(
SWT.COLOR_WIDGET_FOREGROUND));
}
view.getAnnotationFilter().setNameFilterPattern(filterPattern);
view.update();
}
});
// Select the filter pattern if it is equal to the FILTER_HINT_TEXT
TextFocusListener textSelectionOnFocusListener = new TextFocusListener() {
@Override
protected void focusOut(Text text, Event e) {
text.clearSelection();
}
@Override
protected void focusIn(Text text, Event e) {
if(text.getText().equals(AnnotationFilter.FILTER_HINT_TEXT) &&
(e.type != SWT.MouseUp || text.getSelectionCount() == 0)) {
text.selectAll();
}
}
};
nameFilterText.addListener(SWT.FocusIn, textSelectionOnFocusListener);
nameFilterText.addListener(SWT.FocusOut, textSelectionOnFocusListener);
nameFilterText.addListener(SWT.MouseDown, textSelectionOnFocusListener);
nameFilterText.addListener(SWT.MouseUp, textSelectionOnFocusListener);
return nameFilterText;
}
/**
* Creates a {@link Composite} that contains radio buttons to set the scope of the name
* filter (model element names or annotation names).
*/
private Composite createNameFilterScopeComposite(Composite parent,
final GenericAnnotationView view) {
Composite nameFilterScopeComposite = new Composite(parent, SWT.NULL);
nameFilterScopeComposite.setLayout(new RowLayout());
// Radio buttons to select between row and column name filtering
final Label filterLabel = new Label(nameFilterScopeComposite, SWT.NULL);
filterLabel.setText("Filter ");
final Button filterComponentNamesButton = new Button(nameFilterScopeComposite, SWT.RADIO);
filterComponentNamesButton.setText("model element");
filterComponentNamesButton.setSelection(true);
view.getAnnotationFilter().setFilterRowName(true);
filterComponentNamesButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// widgetSelected() is also fired when the selection is removed from the radio
// button, so check, if this is the button that just obtained the selection
if(!((Button)e.getSource()).getSelection()) {
return;
}
view.getAnnotationFilter().setFilterRowName(true);
view.getAnnotationFilter().setFilterColumnName(false);
view.update();
}
});
final Button filterAnnotationNamesButton = new Button(nameFilterScopeComposite, SWT.RADIO);
filterAnnotationNamesButton.setText("annotation names:");
filterAnnotationNamesButton.setSelection(false);
filterAnnotationNamesButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// widgetSelected() is also fired when the selection is removed from the radio
// button, so check, if this is the button that just obtained the selection
if(!((Button)e.getSource()).getSelection()) {
return;
}
view.getAnnotationFilter().setFilterRowName(false);
view.getAnnotationFilter().setFilterColumnName(true);
view.update();
}
});
return nameFilterScopeComposite;
}
/**
* Returns a {@link Button} for setting the options for filtering the
* {@link GenericAnnotationView} for the currently selected model element type.
*
* @param view
* {@link GenericAnnotationView} to be filtered.
*/
private Button createModelElementTypeFilterOptionsCheckButton(Composite parent,
final GenericAnnotationView view) {
// Check box to restrict view to currently selected model element type
final Button filterModelElementTypeButton = new Button(parent, SWT.CHECK);
filterModelElementTypeButton.setText("Show only selected model element type.");
filterModelElementTypeButton.setSelection(false);
filterModelElementTypeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// widgetSelected() is also fired when the selection is removed from the radio
// button, so check, if this is the button that just obtained the selection
view.getAnnotationFilter().setRestrictToSelectedModelElementType(
((Button)e.getSource()).getSelection());
view.update();
}
});
return filterModelElementTypeButton;
}
/**
* Returns a {@link CCombo} for setting the options for filtering the
* {@link GenericAnnotationView} for the model element hierarchy level.
*/
private CCombo createHierarchyLevelFilterOptionsComboBox(Composite parent,
final GenericAnnotationView view) {
// Combo box to select component hierarchy level filter
final CCombo filterHierarchyLevelCombo = new CCombo(parent, SWT.READ_ONLY);
filterHierarchyLevelCombo.add(AnnotationFilter.HIERARCHY_LEVELS_ALL);
filterHierarchyLevelCombo.add(AnnotationFilter.HIERARCHY_LEVELS_CURRENT);
filterHierarchyLevelCombo.add(AnnotationFilter.HIERARCHY_LEVELS_SELECTED_SUBMODEL);
filterHierarchyLevelCombo.select(0);
view.getAnnotationFilter().setHierarchyLevelFilter(filterHierarchyLevelCombo.getText());
filterHierarchyLevelCombo.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
view.getAnnotationFilter().setHierarchyLevelFilter(
filterHierarchyLevelCombo.getText());
view.update();
}
});
return filterHierarchyLevelCombo;
}
/**
* Returns an {@link ExtendedCCombo} for setting the options for filtering the
* {@link GenericAnnotationView} for the annotation type.
*/
private ExtendedCCombo<Class<? extends IAnnotatedSpecification>>
createAnnotationTypeFilterOptionsComboBox(Composite parent,
final GenericAnnotationView view) {
// // Combo box to select annotation type filter
filterAnnotationTypeCombo =
new ExtendedCCombo<Class<? extends IAnnotatedSpecification>>(parent, SWT.READ_ONLY);
updateAnnotationTypeFilterOptionsComboBox(view.getLastAnnotationEntries(), view);
filterAnnotationTypeCombo.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
view.getAnnotationFilter().setAnnotationTypeFilter(
filterAnnotationTypeCombo.getObject(filterAnnotationTypeCombo
.getSelectionIndex()));
view.update();
}
});
return filterAnnotationTypeCombo;
}
/**
* Update the combobox that can be used to configure the annotation type filter based on the
* annotations contained in the current set of annotation entries / model elements (before
* filtering).
*/
public void updateAnnotationTypeFilterOptionsComboBox(
Collection<AnnotationEntry> annotationEntries, GenericAnnotationView view) {
String currentSelection = filterAnnotationTypeCombo.getText();
filterAnnotationTypeCombo.removeAll();
filterAnnotationTypeCombo.add(ANNOTATION_TYPE_ANY, null);
if(annotationEntries != null) {
// Set needed to ensure that each IAnnotatedSpecification which may be contributed
// by more than one AnnotationEntry is added exactly once to the ComboBox.
Set<Class<? extends IAnnotatedSpecification>> annotatedSpecificationClasses =
new HashSet<Class<? extends IAnnotatedSpecification>>();
for(AnnotationEntry annotationEntry : annotationEntries) {
for(IAnnotatedSpecification spec : pickInstanceOf(IAnnotatedSpecification.class,
annotationEntry.getSpecificationsList())) {
if(!annotatedSpecificationClasses.contains(spec.getClass())) {
filterAnnotationTypeCombo.add(
"Show " +
annotationEntry.getSpecificationAnnotationName(spec
.getClass()), spec.getClass());
annotatedSpecificationClasses.add(spec.getClass());
}
}
}
}
// If possible, maintain selected element
int index = filterAnnotationTypeCombo.indexOf(currentSelection);
if(index == -1) {
filterAnnotationTypeCombo.select(0);
view.getAnnotationFilter().setAnnotationTypeFilter(
filterAnnotationTypeCombo.getObject(0));
} else {
filterAnnotationTypeCombo.select(index);
}
// Adjust size to new content
filterAnnotationTypeCombo.pack(true);
}
}
......@@ -18,7 +18,7 @@ $Id$
// Based on http://stackoverflow.com/a/10048884, provided by Stackoverflow user "seand".
// (follow link for license)
package org.fortiss.tooling.base.ui.annotation.view;
package org.fortiss.tooling.base.ui.annotation.view.generic.filter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
......
<!--
$Id$
@version $Rev$
@ConQAT.Rating YELLOW Hash: 220FF5C80574A4AE88C30A7C56D52CE7
-->
<body>
Column and row filters and filter configuration widget for JFace TableViewer based generic annotation view.
</body>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment