Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/NavigationView.java')
-rw-r--r--examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/NavigationView.java109
1 files changed, 64 insertions, 45 deletions
diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/NavigationView.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/NavigationView.java
index 77f69a28d..1b912b4c1 100644
--- a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/NavigationView.java
+++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/NavigationView.java
@@ -17,124 +17,142 @@ import org.eclipse.ui.part.ViewPart;
public class NavigationView extends ViewPart {
public static final String ID = "org.eclipse.equinox.p2.examples.rcp.prestartupdate.navigationView";
private TreeViewer viewer;
-
+
class TreeObject {
private String name;
private TreeParent parent;
-
+
public TreeObject(String name) {
this.name = name;
}
+
public String getName() {
return name;
}
+
public void setParent(TreeParent parent) {
this.parent = parent;
}
+
public TreeParent getParent() {
return parent;
}
+
+ @Override
public String toString() {
return getName();
}
}
-
+
class TreeParent extends TreeObject {
- private ArrayList children;
+ private ArrayList<TreeObject> children;
+
public TreeParent(String name) {
super(name);
- children = new ArrayList();
+ children = new ArrayList<>();
}
+
public void addChild(TreeObject child) {
children.add(child);
child.setParent(this);
}
+
public void removeChild(TreeObject child) {
children.remove(child);
child.setParent(null);
}
+
public TreeObject[] getChildren() {
- return (TreeObject[]) children.toArray(new TreeObject[children.size()]);
+ return children.toArray(new TreeObject[children.size()]);
}
+
public boolean hasChildren() {
- return children.size()>0;
+ return children.size() > 0;
}
}
- class ViewContentProvider implements IStructuredContentProvider,
- ITreeContentProvider {
+ class ViewContentProvider implements IStructuredContentProvider, ITreeContentProvider {
- public void inputChanged(Viewer v, Object oldInput, Object newInput) {
+ @Override
+ public void inputChanged(Viewer v, Object oldInput, Object newInput) {
}
-
+
+ @Override
public void dispose() {
}
-
+
+ @Override
public Object[] getElements(Object parent) {
return getChildren(parent);
}
-
+
+ @Override
public Object getParent(Object child) {
if (child instanceof TreeObject) {
- return ((TreeObject)child).getParent();
+ return ((TreeObject) child).getParent();
}
return null;
}
-
+
+ @Override
public Object[] getChildren(Object parent) {
if (parent instanceof TreeParent) {
- return ((TreeParent)parent).getChildren();
+ return ((TreeParent) parent).getChildren();
}
return new Object[0];
}
- public boolean hasChildren(Object parent) {
+ @Override
+ public boolean hasChildren(Object parent) {
if (parent instanceof TreeParent)
- return ((TreeParent)parent).hasChildren();
+ return ((TreeParent) parent).hasChildren();
return false;
}
}
-
+
class ViewLabelProvider extends LabelProvider {
+ @Override
public String getText(Object obj) {
return obj.toString();
}
+
+ @Override
public Image getImage(Object obj) {
String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
if (obj instanceof TreeParent)
- imageKey = ISharedImages.IMG_OBJ_FOLDER;
+ imageKey = ISharedImages.IMG_OBJ_FOLDER;
return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
}
}
- /**
- * We will set up a dummy model to initialize tree heararchy. In real
- * code, you will connect to a real model and expose its hierarchy.
- */
- private TreeObject createDummyModel() {
- TreeObject to1 = new TreeObject("Inbox");
- TreeObject to2 = new TreeObject("Drafts");
- TreeObject to3 = new TreeObject("Sent");
- TreeParent p1 = new TreeParent("me@this.com");
- p1.addChild(to1);
- p1.addChild(to2);
- p1.addChild(to3);
-
- TreeObject to4 = new TreeObject("Inbox");
- TreeParent p2 = new TreeParent("other@aol.com");
- p2.addChild(to4);
-
- TreeParent root = new TreeParent("");
- root.addChild(p1);
- root.addChild(p2);
- return root;
- }
+ /**
+ * We will set up a dummy model to initialize tree heararchy. In real code, you
+ * will connect to a real model and expose its hierarchy.
+ */
+ private TreeObject createDummyModel() {
+ TreeObject to1 = new TreeObject("Inbox");
+ TreeObject to2 = new TreeObject("Drafts");
+ TreeObject to3 = new TreeObject("Sent");
+ TreeParent p1 = new TreeParent("me@this.com");
+ p1.addChild(to1);
+ p1.addChild(to2);
+ p1.addChild(to3);
+
+ TreeObject to4 = new TreeObject("Inbox");
+ TreeParent p2 = new TreeParent("other@aol.com");
+ p2.addChild(to4);
+
+ TreeParent root = new TreeParent("");
+ root.addChild(p1);
+ root.addChild(p2);
+ return root;
+ }
/**
- * This is a callback that will allow us to create the viewer and initialize
- * it.
- */
+ * 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 | SWT.BORDER);
viewer.setContentProvider(new ViewContentProvider());
@@ -145,6 +163,7 @@ public class NavigationView extends ViewPart {
/**
* Passing the focus request to the viewer's control.
*/
+ @Override
public void setFocus() {
viewer.getControl().setFocus();
}

Back to the top