Skip to content
Snippets Groups Projects
Commit b505f35c authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Completed constraint checker service introspection UI.

refs 2460
parent 0644a658
No related branches found
No related tags found
No related merge requests found
Showing with 305 additions and 58 deletions
......@@ -17,14 +17,23 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.introspection.details.handler;
import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TableLabelProviderBase;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.fortiss.tooling.kernel.extension.IConstraintChecker;
import org.fortiss.tooling.kernel.introspection.IIntrospectionItem;
import org.fortiss.tooling.kernel.introspection.items.ConstraintCheckerServiceIntrospectionDetailsItem;
import org.fortiss.tooling.kernel.service.IConstraintCheckerService;
import org.fortiss.tooling.kernel.ui.internal.introspection.details.DetailsUIHandlerBase;
/**
* The details view for {@link IIntrospectionItem}s provided by {@link IConstraintCheckerService}.
......@@ -35,15 +44,93 @@ import org.fortiss.tooling.kernel.ui.internal.introspection.details.DetailsUIHan
* @ConQAT.Rating RED Hash:
*/
public final class ConstraintCheckerServiceIntrospectionDetailsUIHandler extends
DetailsUIHandlerBase {
/** The tree with filter widget. */
private FilteredTree filteredTree;
FilteredTreeIntrospectionDetailsUIHandlerBase {
/** {@inheritDoc} */
@Override
public Control createComposite(ScrolledComposite parent) {
filteredTree = new FilteredTree(parent, SWT.BORDER, new PatternFilter(), true);
return filteredTree;
FilteredTree ft = createFilteredTree(parent);
Label lbl = new Label(ft, SWT.BOLD);
lbl.setText("Number of registered constraint checkers: " + countCheckers());
return ft;
}
/** Computes the number of constraint checkers. */
private int countCheckers() {
int count = 0;
for(Class<?> c : getInputObject().getHandlerKeyClasses()) {
count += getInputObject().getConstraintChecker(c).size();
}
return count;
}
/** {@inheritDoc} */
@Override
protected void createTreeColumns(Tree tree) {
TreeColumn col0 = new TreeColumn(tree, SWT.LEFT);
col0.setText("Model Element Class");
col0.setWidth(400);
TreeColumn col1 = new TreeColumn(tree, SWT.LEFT);
col1.setText("Constraint Checker Class");
col1.setWidth(400);
}
/** {@inheritDoc} */
@Override
protected ITreeContentProvider createContentProvider() {
return new TreeContentProviderBase() {
@Override
public Object[] getChildren(Object parentElement) {
if(parentElement == getInputObject()) {
return getInputObject().getHandlerKeyClasses().toArray();
} else if(parentElement instanceof Class) {
return getInputObject().getConstraintChecker((Class<?>)parentElement).toArray();
}
return null;
}
};
}
/** {@inheritDoc} */
@Override
protected ITableLabelProvider createLabelProvider() {
return new TableLabelProviderBase() {
@SuppressWarnings("unchecked")
@Override
public String getColumnText(Object element, int columnIndex) {
if(element instanceof Class) {
switch(columnIndex) {
case 0:
return ((Class<?>)element).getSimpleName();
case 1:
return ((Class<?>)element).getName();
}
} else if(element instanceof IConstraintChecker) {
IConstraintChecker<EObject> icc = (IConstraintChecker<EObject>)element;
switch(columnIndex) {
case 0:
return icc.getClass().getSimpleName();
case 1:
return icc.getClass().getName();
}
}
return "";
}
};
}
/** {@inheritDoc} */
@Override
protected PatternFilter createPatternFilter() {
return new TableViewerPatternFilter();
}
/** {@inheritDoc} */
@Override
protected ConstraintCheckerServiceIntrospectionDetailsItem getInputObject() {
return (ConstraintCheckerServiceIntrospectionDetailsItem)dataItem;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2016 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.kernel.ui.internal.introspection.details.handler;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.fortiss.tooling.kernel.ui.internal.introspection.details.DetailsUIHandlerBase;
/**
* Base class for details UI implementations with filtered tree viewer.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class FilteredTreeIntrospectionDetailsUIHandlerBase extends DetailsUIHandlerBase {
/** Creates the filtered tree control. */
protected final FilteredTree createFilteredTree(Composite parent) {
FilteredTree filteredTree =
new FilteredTree(parent, SWT.BORDER, createPatternFilter(), true);
TreeViewer treeViewer = filteredTree.getViewer();
Tree tree = treeViewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
createTreeColumns(tree);
treeViewer.setContentProvider(createContentProvider());
treeViewer.setLabelProvider(createLabelProvider());
treeViewer.setInput(getInputObject());
return filteredTree;
}
/** Create the columns of the tree. */
protected abstract void createTreeColumns(Tree tree);
/** Creates the content provider. */
protected abstract ITreeContentProvider createContentProvider();
/** Creates the label provider. */
protected abstract ITableLabelProvider createLabelProvider();
/** Creates the pattern filter. */
protected abstract PatternFilter createPatternFilter();
/** Returns the input object for the tree viewer. */
protected abstract Object getInputObject();
}
......@@ -18,10 +18,9 @@ $Id$
package org.fortiss.tooling.kernel.ui.internal.introspection.details.handler;
import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TableLabelProviderBase;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Control;
......@@ -34,46 +33,42 @@ import org.fortiss.tooling.kernel.extension.IPrototypeProvider;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.extension.data.PrototypeCategory;
import org.fortiss.tooling.kernel.service.IPrototypeService;
import org.fortiss.tooling.kernel.ui.internal.introspection.details.DetailsUIHandlerBase;
/**
* UI handler for the {@link IPrototypeService}.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public final class PrototypeServiceIntrospectionDetailsUIHandler extends DetailsUIHandlerBase {
/** The tree with filter widget. */
private FilteredTree filteredTree;
public final class PrototypeServiceIntrospectionDetailsUIHandler extends
FilteredTreeIntrospectionDetailsUIHandlerBase {
/** {@inheritDoc} */
@Override
public Control createComposite(ScrolledComposite parent) {
filteredTree = new FilteredTree(parent, SWT.BORDER, new PatternFilter() {
/** {@inheritDoc} */
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
TreeViewer tv = (TreeViewer)viewer;
int nCols = tv.getTree().getColumnCount();
boolean isMatch = false;
for(int columnIndex = 0; columnIndex < nCols; columnIndex++) {
ColumnLabelProvider labelProvider =
(ColumnLabelProvider)tv.getLabelProvider(columnIndex);
String labelText = labelProvider.getText(element);
isMatch |= wordMatches(labelText);
}
return isMatch;
}
}, true);
createCounterLabel();
FilteredTree filteredTree = createFilteredTree(parent);
Label lbl = new Label(filteredTree, SWT.NONE);
lbl.setText("Number of currently registered prototypes: " +
IPrototypeService.INSTANCE.getAllPrototypes().size() + " (" +
IPrototypeService.INSTANCE.getPrimaryPrototypes().size() + " primary prototypes)");
return filteredTree;
}
TreeViewer treeViewer = filteredTree.getViewer();
Tree tree = treeViewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
/** Find the prototype provider for the given prototype. */
private String findProtoypeProviderClassName(Prototype proto) {
for(IPrototypeProvider provider : IPrototypeService.INSTANCE.getPrototypeProviders()) {
if(provider.getPrototypes().contains(proto)) {
return provider.getClass().getName();
}
}
return "Unknown Prototype Provider!";
}
/** {@inheritDoc} */
@Override
protected void createTreeColumns(Tree tree) {
TreeColumn col0 = new TreeColumn(tree, SWT.LEFT);
col0.setText("Category / Prototype");
col0.setWidth(200);
......@@ -89,8 +84,12 @@ public final class PrototypeServiceIntrospectionDetailsUIHandler extends Details
TreeColumn col3 = new TreeColumn(tree, SWT.CENTER);
col3.setText("Primary");
col3.setWidth(40);
}
treeViewer.setContentProvider(new TreeContentProviderBase() {
/** {@inheritDoc} */
@Override
protected ITreeContentProvider createContentProvider() {
return new TreeContentProviderBase() {
@Override
public Object[] getChildren(Object parentElement) {
......@@ -105,9 +104,13 @@ public final class PrototypeServiceIntrospectionDetailsUIHandler extends Details
return null;
}
});
};
}
treeViewer.setLabelProvider(new TableLabelProviderBase() {
/** {@inheritDoc} */
@Override
protected ITableLabelProvider createLabelProvider() {
return new TableLabelProviderBase() {
@Override
public String getColumnText(Object parentElement, int columnIndex) {
if(parentElement instanceof IPrototypeService) {
......@@ -132,27 +135,18 @@ public final class PrototypeServiceIntrospectionDetailsUIHandler extends Details
}
return "";
}
});
treeViewer.setInput(IPrototypeService.INSTANCE);
return filteredTree;
};
}
/** Creates the label for counters of registered prototypes. */
private void createCounterLabel() {
Label lbl = new Label(filteredTree, SWT.NONE);
lbl.setText("Number of currently registered prototypes: " +
IPrototypeService.INSTANCE.getAllPrototypes().size() + " (" +
IPrototypeService.INSTANCE.getPrimaryPrototypes().size() + " primary prototypes)");
/** {@inheritDoc} */
@Override
protected PatternFilter createPatternFilter() {
return new TableViewerPatternFilter();
}
/** Find the prototype provider for the given prototype. */
private String findProtoypeProviderClassName(Prototype proto) {
for(IPrototypeProvider provider : IPrototypeService.INSTANCE.getPrototypeProviders()) {
if(provider.getPrototypes().contains(proto)) {
return provider.getClass().getName();
}
}
return "Unknown Prototype Provider!";
/** {@inheritDoc} */
@Override
protected Object getInputObject() {
return IPrototypeService.INSTANCE;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2016 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.kernel.ui.internal.introspection.details.handler;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.dialogs.PatternFilter;
/**
* Class for tree table viewer {@link PatternFilter}s.
* Sub-classes should override {@link #basicMatch(String, int)}.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
class TableViewerPatternFilter extends PatternFilter {
/** {@inheritDoc} */
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
TreeViewer tv = (TreeViewer)viewer;
int nCols = tv.getTree().getColumnCount();
boolean isMatch = false;
for(int columnIndex = 0; columnIndex < nCols; columnIndex++) {
ColumnLabelProvider labelProvider =
(ColumnLabelProvider)tv.getLabelProvider(columnIndex);
String labelText = labelProvider.getText(element);
isMatch |= basicMatch(labelText, columnIndex);
}
return isMatch;
}
/** Matches the label in the given column. */
@SuppressWarnings("unused")
protected boolean basicMatch(String labelText, int columnIndex) {
return wordMatches(labelText);
}
}
......@@ -18,6 +18,7 @@ $Id$
package org.fortiss.tooling.kernel.internal;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableMap;
import java.util.ArrayList;
import java.util.Collections;
......@@ -166,6 +167,6 @@ public class ConstraintCheckerService extends EObjectAwareServiceBase<IConstrain
/** {@inheritDoc} */
@Override
public IIntrospectionDetailsItem getDetailsItem() {
return new ConstraintCheckerServiceIntrospectionDetailsItem();
return new ConstraintCheckerServiceIntrospectionDetailsItem(unmodifiableMap(handlerMap));
}
}
......@@ -17,9 +17,21 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.introspection.items;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.IConstraintChecker;
import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
import org.fortiss.tooling.kernel.service.IConstraintCheckerService;
/**
* {@link IIntrospectionDetailsItem} for the {@link IConstraintCheckerService}.
*
* @author hoelzl
* @author $Author$
......@@ -28,4 +40,31 @@ import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
*/
public class ConstraintCheckerServiceIntrospectionDetailsItem implements IIntrospectionDetailsItem {
/** Read-only copy of the services handler list. */
private final Map<Class<?>, List<IConstraintChecker<EObject>>> handlerMap;
/** Constructor. */
public ConstraintCheckerServiceIntrospectionDetailsItem(
Map<Class<?>, List<IConstraintChecker<EObject>>> handlerMap) {
this.handlerMap = handlerMap;
}
/** Returns the handler map. */
public Map<Class<?>, List<IConstraintChecker<EObject>>> getHandlerMap() {
return handlerMap;
}
/** Returns the registration classes- */
public Collection<Class<?>> getHandlerKeyClasses() {
return unmodifiableSet(handlerMap.keySet());
}
/** Returns the ICC for the given registration class. */
public List<IConstraintChecker<EObject>> getConstraintChecker(Class<?> regClass) {
List<IConstraintChecker<EObject>> l = handlerMap.get(regClass);
if(l != null) {
return unmodifiableList(l);
}
return emptyList();
}
}
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