1 | package de.uka.ipd.sdq.cip.runtime.runconfig.tabs; |
2 | |
3 | import java.util.ArrayList; |
4 | |
5 | import org.eclipse.debug.core.ILaunchConfiguration; |
6 | import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
7 | import org.eclipse.jface.viewers.ArrayContentProvider; |
8 | import org.eclipse.jface.viewers.ITreeContentProvider; |
9 | import org.eclipse.jface.viewers.LabelProvider; |
10 | import org.eclipse.jface.viewers.TreeViewer; |
11 | import org.eclipse.swt.SWT; |
12 | import org.eclipse.swt.layout.GridData; |
13 | import org.eclipse.swt.layout.GridLayout; |
14 | import org.eclipse.swt.widgets.Composite; |
15 | import org.eclipse.swt.widgets.Label; |
16 | |
17 | |
18 | public class CipModelTab extends AbstractCipLaunchConfigurationTab { |
19 | |
20 | private class ModelList { |
21 | public String name; |
22 | public ArrayList<String> models; |
23 | |
24 | public ModelList(String name) { |
25 | models = new ArrayList<String>(); |
26 | this.name = name; |
27 | } |
28 | } |
29 | |
30 | private TreeViewer modelfilesViewer; |
31 | private ModelList[] modelList; |
32 | |
33 | @Override |
34 | public void createControl(Composite parent) { |
35 | Composite mainComponent = new Composite(parent,SWT.NONE); |
36 | setControl(mainComponent); |
37 | |
38 | mainComponent.setFont(parent.getFont()); |
39 | |
40 | GridLayout layout = new GridLayout(3, false); |
41 | layout.marginWidth = 5; |
42 | layout.marginHeight = 5; |
43 | mainComponent.setLayout(layout); |
44 | |
45 | Label label = new Label(mainComponent,SWT.LEFT); |
46 | label.setText("Transformations:"); |
47 | GridData gd = new GridData(SWT.FILL,SWT.TOP,true,false); |
48 | gd.horizontalSpan = 3; |
49 | label.setLayoutData(gd); |
50 | modelfilesViewer = createTree(mainComponent); |
51 | gd = new GridData(SWT.FILL,SWT.FILL,true,false); |
52 | //gd.horizontalSpan = ; |
53 | modelfilesViewer.getTree().setLayoutData(gd); |
54 | |
55 | } |
56 | |
57 | private TreeViewer createTree(Composite mainComponent) { |
58 | |
59 | final TreeViewer treeviewer; |
60 | |
61 | treeviewer = new TreeViewer(mainComponent,SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); |
62 | treeviewer.setLabelProvider(new ModelInputOutputLabelProvider()); |
63 | treeviewer.setContentProvider(new ModelInputOutputContentProvider()); |
64 | modelList = new ModelList[2]; |
65 | modelList[0] = new ModelList("Input Models"); |
66 | modelList[1] = new ModelList("Output Models"); |
67 | treeviewer.setInput(modelList); |
68 | return treeviewer; |
69 | } |
70 | |
71 | @Override |
72 | public String getName() { |
73 | return "CIP Input/Output Models"; |
74 | } |
75 | |
76 | @Override |
77 | public void initializeFrom(ILaunchConfiguration configuration) { |
78 | // TODO Auto-generated method stub |
79 | |
80 | } |
81 | |
82 | @Override |
83 | public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
84 | // TODO Auto-generated method stub |
85 | |
86 | } |
87 | |
88 | @Override |
89 | public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
90 | // TODO Auto-generated method stub |
91 | |
92 | } |
93 | |
94 | public class ModelInputOutputContentProvider extends ArrayContentProvider implements ITreeContentProvider { |
95 | |
96 | @Override |
97 | public Object[] getChildren(Object parentElement) { |
98 | if(parentElement instanceof ModelList) |
99 | { |
100 | ModelList modelList = (ModelList) parentElement; |
101 | return modelList.models.toArray(); |
102 | } |
103 | return null; |
104 | } |
105 | |
106 | @Override |
107 | public Object getParent(Object element) { |
108 | // TODO Auto-generated method stub |
109 | return null; |
110 | } |
111 | |
112 | @Override |
113 | public boolean hasChildren(Object element) { |
114 | if(element instanceof ModelList) |
115 | { |
116 | ModelList modelList = (ModelList) element; |
117 | return modelList.models.size() > 0; |
118 | } |
119 | return false; |
120 | } |
121 | |
122 | } |
123 | |
124 | public class ModelInputOutputLabelProvider extends LabelProvider { |
125 | |
126 | @Override |
127 | public String getText(Object element) { |
128 | if(element instanceof ModelList) |
129 | { |
130 | ModelList modelList = (ModelList) element; |
131 | return modelList.name; |
132 | } |
133 | return (String)element; |
134 | } |
135 | |
136 | } |
137 | |
138 | } |