1 | package de.uka.ipd.sdq.codegen.simucontroller.gui; |
2 | |
3 | import java.util.HashMap; |
4 | import java.util.Observable; |
5 | import java.util.Observer; |
6 | |
7 | import org.eclipse.swt.SWT; |
8 | import org.eclipse.swt.layout.FillLayout; |
9 | import org.eclipse.swt.widgets.Composite; |
10 | import org.eclipse.ui.PlatformUI; |
11 | import org.eclipse.ui.part.ViewPart; |
12 | |
13 | import de.uka.ipd.sdq.codegen.simucontroller.SimuControllerPlugin; |
14 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.DockModel; |
15 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.DocksModel; |
16 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockAddedEvent; |
17 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockDeletedEvent; |
18 | |
19 | public class DockStatusViewPart extends ViewPart implements Observer { |
20 | |
21 | public static final String ID = "de.uka.ipd.sdq.codegen.simucontroller.gui.DockStatusViewPart"; //$NON-NLS-1$ |
22 | private HashMap<String,DockStatusViewer> viewers = new HashMap<String, DockStatusViewer>(); |
23 | private DocksModel model; |
24 | private Composite container; |
25 | |
26 | /** |
27 | * Create contents of the view part |
28 | * @param parent |
29 | */ |
30 | @Override |
31 | public void createPartControl(Composite parent) { |
32 | container = new Composite(parent, SWT.NONE); |
33 | container.setLayout(new FillLayout()); |
34 | model = SimuControllerPlugin.getDockModel(); |
35 | |
36 | for(DockModel dock : model.getAllDocks()) { |
37 | update(model,new DockAddedEvent(dock)); |
38 | } |
39 | model.addObserver(this); |
40 | |
41 | createActions(); |
42 | } |
43 | |
44 | @Override |
45 | public void dispose() { |
46 | model.deleteObserver(this); |
47 | super.dispose(); |
48 | } |
49 | |
50 | /** |
51 | * Create the actions |
52 | */ |
53 | private void createActions() { |
54 | // Create the actions |
55 | } |
56 | |
57 | @Override |
58 | public void setFocus() { |
59 | // Set the focus |
60 | } |
61 | |
62 | public void update(Observable o, Object arg) { |
63 | if (arg instanceof DockAddedEvent) { |
64 | final DockAddedEvent addedEvent = (DockAddedEvent) arg; |
65 | PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable(){ |
66 | |
67 | public void run() { |
68 | DockStatusViewPart.this.viewers.put(addedEvent.getDock().getID(), |
69 | new DockStatusViewer(addedEvent.getDock(),container,SWT.NONE)); |
70 | container.layout(); |
71 | container.redraw(); |
72 | } |
73 | |
74 | }); |
75 | } |
76 | if (arg instanceof DockDeletedEvent) { |
77 | final DockDeletedEvent deleteEvent = (DockDeletedEvent) arg; |
78 | PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable(){ |
79 | |
80 | public void run() { |
81 | DockStatusViewer viewer = DockStatusViewPart.this.viewers.get(deleteEvent.getDock().getID()); |
82 | DockStatusViewPart.this.viewers.remove(deleteEvent.getDock().getID()); |
83 | viewer.dispose(); |
84 | container.layout(); |
85 | container.redraw(); |
86 | } |
87 | |
88 | }); |
89 | } |
90 | } |
91 | |
92 | } |