Commit c27a50ed authored by Johannes Eder's avatar Johannes Eder
Browse files

removed unused view

Issue-Ref: 3886
Issue-Url: https://af3-developer.fortiss.org/issues/3886

Signed-off-by: Johannes Eder's avatarJohannes Eder <eder@fortiss.org>
parent 26b1df4a
......@@ -24,5 +24,4 @@ Export-Package: org.fortiss.af3.mira.ui,
org.fortiss.af3.mira.ui.editorbinding,
org.fortiss.af3.mira.ui.handler,
org.fortiss.af3.mira.ui.utils,
org.fortiss.af3.mira.ui.views,
test.org.fortiss.af3.mira.ui
......@@ -99,14 +99,5 @@
id="org.fortiss.af3.mira"
name="AutoFocus">
</category>
<view
allowMultiple="false"
category="org.fortiss.af3.mira"
class="org.fortiss.af3.mira.ui.views.RequirementHierarchyView"
icon="icons/sample.gif"
id="org.fortiss.af3.mira.ui.views.RequirementHierarchyView"
name="Requirement Hierarchy"
restorable="false">
</view>
</extension>
</plugin>
RequirementHierarchyView.java d99ea6f5b464621111d5c9c47cc7140cc287047b GREEN
/*-------------------------------------------------------------------------+
| Copyright 2011 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.af3.mira.ui.views;
import static org.eclipse.core.runtime.Assert.isNotNull;
import static org.eclipse.wb.swt.ResourceManager.getPluginImage;
import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.checkAndPickFirst;
import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeSet;
import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.RequirementRelation;
import org.fortiss.af3.mira.model.relations.DefinedRequirementRelationType;
import org.fortiss.af3.mira.model.relations.DirectedRequirementRelationType;
import org.fortiss.af3.mira.model.relations.RequirementRelationType;
import org.fortiss.af3.mira.model.relations.UndirectedRequirementRelationType;
import org.fortiss.af3.mira.relation.IRelationTypeHandler;
import org.fortiss.af3.mira.relation.IRelationTypeService;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/**
* {@link ViewPart} to show the relations of a given requirement
*
* @author mou
*/
public class RequirementHierarchyView extends ViewPart {
/** The label provider for the view. */
public class RequirementHierarchyLabelProvider extends LabelProvider {
/** {@inheritDoc} */
@Override
public String getText(Object obj) {
return RequirementHierarchyView.this.getText(obj);
}
/** {@inheritDoc} */
@Override
public Image getImage(Object obj) {
if(obj instanceof EObject) {
return IModelElementHandlerService.getInstance()
.getModelElementHandler((EObject)obj).getIcon((EObject)obj);
} else if(obj instanceof Node) {
return getImage(((Node)obj).req);
} else if(obj instanceof Category) {
Category c = (Category)obj;
if(!c.directed) {
return getPluginImage("org.eclipse.ui", "/icons/full/elcl16/synced.gif");
} else if(c.incoming) {
return getPluginImage("org.eclipse.ui", "/icons/full/elcl16/backward_nav.gif");
} else if(c.outgoing) {
return getPluginImage("org.eclipse.ui", "/icons/full/elcl16/forward_nav.gif");
}
return getPluginImage("org.eclipse.ui", "/icons/full/elcl16/progress_stop.gif");
}
throw new IllegalArgumentException();
}
}
/** The tree content provider for the view. */
public class RequirementHierarchyTreeContentProvider extends TreeContentProviderBase {
/** {@inheritDoc} */
@Override
public Object[] getElements(Object parent) {
if(root != null) {
return new Object[] {new Node(null, root.req)};
}
return new Object[0];
}
/** {@inheritDoc} */
@Override
public Object getParent(Object child) {
if(child instanceof Node) {
return ((Node)child).parent;
} else if(child instanceof Category) {
return ((Category)child).node;
}
throw new IllegalArgumentException();
}
/** {@inheritDoc} */
@Override
public Object[] getChildren(Object parent) {
if(parent instanceof Node) {
return getChildren((Node)parent);
} else if(parent instanceof Category) {
return getChildren((Category)parent);
}
throw new IllegalArgumentException();
}
/** get all categories */
private Object[] getChildren(Node parent) {
Requirement req = parent.req;
HashMap<String, Category> children = new HashMap<String, Category>();
for(RequirementRelation rel : req.getIncomingRequirementRelation()) {
RequirementRelationType relationType = rel.getRequirementRelationType();
if((relationType instanceof DirectedRequirementRelationType &&
rel.getSourceRequirement().size() > 0) ||
(relationType instanceof UndirectedRequirementRelationType &&
rel.getTargetRequirement().size() > 1)) {
Category c = new Category(parent, true, relationType);
children.put(getText(c), c);
}
}
for(RequirementRelation rel : req.getOutgoingRequirementRelation()) {
if(rel.getTargetRequirement().size() > 0) {
Category c = new Category(parent, false, rel.getRequirementRelationType());
children.put(getText(c), c);
}
}
return children.values().toArray();
}
/** get sub nodes */
private Object[] getChildren(Category category) {
Requirement req = category.node.req;
TreeSet<Node> children = new TreeSet<Node>(new Comparator<Node>() {
@Override
public int compare(Node o1, Node o2) {
return o1.req.getReqId().compareTo(o2.req.getReqId());
}
});
if(!category.directed && category.incoming) {
for(RequirementRelation rel : req.getIncomingRequirementRelation()) {
if(rel.getTargetRequirement().size() > 1 &&
category.handlerEqualsRequirementRelationType(rel)) {
addNodesFromListToTree(children, rel.getTargetRequirement(), req, category);
}
}
}
if(category.directed && category.incoming) {
for(RequirementRelation rel : req.getIncomingRequirementRelation()) {
if(rel.getSourceRequirement().size() > 0 &&
category.handlerEqualsRequirementRelationType(rel)) {
addNodesFromListToTree(children, rel.getSourceRequirement(), req, category);
}
}
}
if(category.directed && category.outgoing) {
for(RequirementRelation rel : req.getOutgoingRequirementRelation()) {
if(rel.getTargetRequirement().size() > 0 &&
category.handlerEqualsRequirementRelationType(rel)) {
addNodesFromListToTree(children, rel.getTargetRequirement(), req, category);
}
}
}
return children.toArray();
}
/**
* add nodes to tree
*/
private void addNodesFromListToTree(TreeSet<Node> tree, EList<Requirement> reqList,
Requirement req, Category category) {
for(Requirement reqToAdd : reqList) {
if(!reqToAdd.equals(req)) {
tree.add(new Node(category, reqToAdd));
}
}
}
}
/** The node which contains a requirement. */
private class Node {
/** the parent category */
public Category parent;
/** the hold requirement */
public Requirement req;
/** Constructor */
public Node(Category parent, Requirement req) {
Assert.isNotNull(req);
this.parent = parent;
this.req = req;
}
}
/** The relation category for a type of relation. */
private class Category {
/** the node with link to parent category */
public Node node;
/** incoming flag */
public boolean incoming;
/** outgoing flag */
public boolean outgoing;
/** undirected flag */
public boolean directed;
/** relation type */
public RequirementRelationType type;
/** handler */
public IRelationTypeHandler<RequirementRelationType> handler;
/** Constructor */
public Category(Node node, boolean isIncoming, RequirementRelationType type) {
isNotNull(node);
this.node = node;
this.incoming = isIncoming;
this.outgoing = !isIncoming;
this.directed = type instanceof DirectedRequirementRelationType;
this.type = type;
handler = IRelationTypeService.getInstance().getHandler(type);
}
/** handler of category equals handler of {@link RequirementRelationType} */
public boolean handlerEqualsRequirementRelationType(RequirementRelation rel) {
return this.handler.equals(IRelationTypeService.getInstance()
.getHandler(rel.getRequirementRelationType()));
}
}
/** The tree viewer. */
private TreeViewer viewer;
/** The root requirement. */
private Node root;
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
@Override
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new RequirementHierarchyTreeContentProvider());
viewer.setLabelProvider(new RequirementHierarchyLabelProvider());
viewer.setInput(getViewSite());
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
Node node = checkAndPickFirst(event.getSelection(), Node.class);
if(node == null)
return;
IModelEditorBindingService.getInstance().openInEditor(node.req);
}
});
}
/** Passing the focus request to the viewer's control. */
@Override
public void setFocus() {
viewer.getControl().setFocus();
}
/** Set the requirement input. */
public void setInput(Requirement r) {
root = new Node(null, r);
viewer.setInput(root);
}
/** Get display name of a node or category. */
private String getText(Object obj) {
if(obj instanceof Node) {
Requirement r = ((Node)obj).req;
return IModelElementHandlerService.getInstance().getModelElementHandler(r).getName(r);
} else if(obj instanceof Category) {
Category c = (Category)obj;
if(c.type instanceof DefinedRequirementRelationType) {
return ((DefinedRequirementRelationType)c.type).getName();
}
if(!c.directed) {
return c.handler.getDisplayNameForSource();
} else if(c.incoming) {
return c.handler.getDisplayNameForSource();
} else if(c.outgoing) {
return c.handler.getDisplayNameForTarget();
}
return "Unknown relation";
}
throw new IllegalArgumentException();
}
}
<!-- (c) 2017 fortiss GmbH -->
<body>
Package for views
</body>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment