1 | package de.uka.ipd.sdq.pcm.dialogs.parameters; |
2 | |
3 | import java.util.ArrayList; |
4 | |
5 | import org.eclipse.emf.ecore.EReference; |
6 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
7 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; |
8 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
9 | import org.eclipse.emf.transaction.util.TransactionUtil; |
10 | import org.eclipse.jface.dialogs.IDialogConstants; |
11 | import org.eclipse.jface.dialogs.TitleAreaDialog; |
12 | import org.eclipse.swt.SWT; |
13 | import org.eclipse.swt.graphics.Point; |
14 | import org.eclipse.swt.layout.FormLayout; |
15 | import org.eclipse.swt.layout.GridData; |
16 | import org.eclipse.swt.widgets.Composite; |
17 | import org.eclipse.swt.widgets.Control; |
18 | import org.eclipse.swt.widgets.Shell; |
19 | |
20 | import de.uka.ipd.sdq.dialogs.selection.FilteredItemsAdapterFactory; |
21 | import de.uka.ipd.sdq.pcm.dialogs.Messages; |
22 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
23 | import de.uka.ipd.sdq.pcm.repository.Signature; |
24 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
25 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
26 | |
27 | /** |
28 | * @author Roman Andrej |
29 | * |
30 | * The dialogue serves the input of parameter names and types in table cells. It |
31 | * a simple editor implemented for providing and deletion of types. |
32 | */ |
33 | public class ParametersDialog extends TitleAreaDialog { |
34 | |
35 | private ComposedAdapterFactory adapterFactory; |
36 | |
37 | private Signature signature; |
38 | |
39 | /** |
40 | * Creates a dialog with the given parent and edited properties name |
41 | * |
42 | * @param parentShell |
43 | * -object that returns the current parent shell columnName - |
44 | * edited properties |
45 | */ |
46 | public ParametersDialog(Shell parentShell, Signature signature) { |
47 | super(parentShell); |
48 | this.signature = signature; |
49 | |
50 | /** |
51 | * the result of combining the constants which are required |
52 | * to produce a typical application top level shell |
53 | */ |
54 | setShellStyle(SWT.RESIZE|SWT.TITLE|SWT.CLOSE |SWT.MIN|SWT.MAX); |
55 | } |
56 | |
57 | /* (non-Javadoc) |
58 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) |
59 | */ |
60 | @Override |
61 | protected void configureShell(Shell newShell) { |
62 | super.configureShell(newShell); |
63 | newShell.setText("OwnedParameters"); |
64 | } |
65 | |
66 | /* (non-Javadoc) |
67 | * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
68 | */ |
69 | @Override |
70 | protected Control createDialogArea(Composite parent) { |
71 | setTitle(Messages.ParametersDialog_Title); |
72 | |
73 | Composite area = (Composite) super.createDialogArea(parent); |
74 | Composite container = new Composite(area, SWT.NONE); |
75 | container.setLayout(new FormLayout()); |
76 | container.setLayoutData(new GridData(GridData.FILL_BOTH)); |
77 | |
78 | ArrayList<Object> filterList = new ArrayList<Object>(); |
79 | filterList.add(Parameter.class); |
80 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
81 | |
82 | adapterFactory = new ComposedAdapterFactory(); |
83 | adapterFactory |
84 | .addAdapterFactory(new RepositoryItemProviderAdapterFactory()); |
85 | |
86 | CreateEditorContents editorContents = CreateEditorContents |
87 | .create(container); |
88 | |
89 | editorContents |
90 | .setViewerContentProvider(new AdapterFactoryContentProvider( |
91 | new FilteredItemsAdapterFactory(adapterFactory, |
92 | filterList, additionalReferences))); |
93 | editorContents |
94 | .setViewerLabelProvider(new AdapterFactoryLabelProvider( |
95 | new ParametersItemProviderAdapterFactory( |
96 | new PalladioItemProviderAdapterFactory( |
97 | adapterFactory)))); |
98 | editorContents.setViewerCellModifier(new ParametersCellModifier( |
99 | editorContents.getViewer(), TransactionUtil |
100 | .getEditingDomain(signature))); |
101 | editorContents.createNameColumnCellEditor(); |
102 | editorContents.createTypeColumnCellEditor(TransactionUtil |
103 | .getEditingDomain(signature)); |
104 | editorContents.setAddButtonActionListener(new AddParameterAction( |
105 | signature)); |
106 | |
107 | DeleteParameterAction deleteParameterAction = new DeleteParameterAction( |
108 | signature); |
109 | UpParameterAction upParameterAction = new UpParameterAction(signature); |
110 | DownParameterAction downParameterAction = new DownParameterAction( |
111 | signature); |
112 | |
113 | editorContents.setDeleteButtonActionListener(deleteParameterAction); |
114 | editorContents.setUpButtonActionListener(upParameterAction); |
115 | editorContents.setDownButtonActionListener(downParameterAction); |
116 | |
117 | editorContents.setViewerSelectionChangedListener(deleteParameterAction); |
118 | editorContents.setViewerSelectionChangedListener(upParameterAction); |
119 | editorContents.setViewerSelectionChangedListener(downParameterAction); |
120 | |
121 | editorContents.setViewerInput(signature); |
122 | |
123 | /** create separatot to button area */ |
124 | ((CreateEditorContents) editorContents).createSeparator(parent); |
125 | |
126 | return area; |
127 | } |
128 | |
129 | /* |
130 | * (non-Javadoc) |
131 | * |
132 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) |
133 | */ |
134 | @Override |
135 | protected void createButtonsForButtonBar(Composite parent) { |
136 | createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, |
137 | false); |
138 | } |
139 | |
140 | /* (non-Javadoc) |
141 | * @see org.eclipse.jface.dialogs.TitleAreaDialog#getInitialSize() |
142 | */ |
143 | @Override |
144 | protected Point getInitialSize() { |
145 | return new Point(500, 375); |
146 | } |
147 | } |