KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > person > preferences > PersonStructOrderComposite


1 package com.nightlabs.ipanema.person.preferences;
2
3 import java.util.Map JavaDoc;
4
5 import org.eclipse.jface.viewers.IStructuredSelection;
6 import org.eclipse.jface.viewers.TableLayout;
7 import org.eclipse.jface.viewers.TableViewer;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.SelectionEvent;
10 import org.eclipse.swt.events.SelectionListener;
11 import org.eclipse.swt.graphics.Point;
12 import org.eclipse.swt.graphics.Rectangle;
13 import org.eclipse.swt.layout.FillLayout;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.layout.RowLayout;
17 import org.eclipse.swt.widgets.Button;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Display;
20 import org.eclipse.swt.widgets.Group;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.swt.widgets.Table;
24 import org.eclipse.swt.widgets.TableColumn;
25
26 import com.nightlabs.ipanema.base.IpanemaBasePlugin;
27
28
29
30 /**
31  *
32  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
33  */

34 public class PersonStructOrderComposite extends Composite {
35     private Composite titleComposite;
36     private Label labelTitle;
37     private Group groupStructBlocks;
38     private Button buttonFieldDown;
39     private Button buttonFieldUp;
40     private Composite fieldsTableComposite;
41     private Composite fieldsButtonsComposite;
42     private Button buttonBlockDown;
43     private Button buttonBlockUp;
44     private Composite blocksButtonsComposite;
45     private Composite blocksTableComposite;
46     private Group groupStructFields;
47     
48     
49     private TableViewer tableViewerBlocks;
50     private TableViewer tableViewerFields;
51     
52     
53     public static void showGUI() {
54         Display display = Display.getDefault();
55         Shell shell = new Shell(display);
56         PersonStructOrderComposite inst = new PersonStructOrderComposite(shell, SWT.NULL);
57         Point size = inst.getSize();
58         shell.setLayout(new FillLayout());
59         shell.layout();
60         if(size.x == 0 && size.y == 0) {
61             inst.pack();
62             shell.pack();
63         } else {
64             Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
65             int MENU_HEIGHT = 22;
66             if (shell.getMenuBar() != null)
67                 shellBounds.height -= MENU_HEIGHT;
68             shell.setSize(shellBounds.width, shellBounds.height);
69         }
70         shell.open();
71         while (!shell.isDisposed()) {
72             if (!display.readAndDispatch())
73                 display.sleep();
74         }
75     }
76     
77     
78     /**
79      *
80      * @param parent
81      * @param style
82      */

83     public PersonStructOrderComposite(Composite parent, int style) {
84         super(parent, style);
85         GridLayout thisLayout = new GridLayout();
86         thisLayout.numColumns = 2;
87         thisLayout.makeColumnsEqualWidth = true;
88         this.setLayout(thisLayout);
89         
90         GridData thisData = new GridData(GridData.FILL_BOTH);
91         this.setLayoutData(thisData);
92
93         titleComposite = new Composite(this, SWT.NONE);
94         RowLayout titleCompositeLayout = new RowLayout(org.eclipse.swt.SWT.HORIZONTAL);
95         GridData titleCompositeLData = new GridData();
96         titleCompositeLData.grabExcessHorizontalSpace = true;
97         titleCompositeLData.horizontalSpan = 2;
98         titleCompositeLData.horizontalAlignment = GridData.FILL;
99         titleComposite.setLayoutData(titleCompositeLData);
100         titleComposite.setLayout(titleCompositeLayout);
101         
102         labelTitle = new Label(titleComposite, SWT.NONE | SWT.WRAP);
103         labelTitle.setText("Define the display order of the person structure");
104         
105         groupStructBlocks = new Group(this, SWT.NONE);
106         GridLayout groupStructBlocksLayout = new GridLayout();
107         groupStructBlocksLayout.numColumns = 2;
108         groupStructBlocksLayout.horizontalSpacing = 0;
109         groupStructBlocksLayout.marginWidth = 0;
110         groupStructBlocksLayout.marginHeight = 0;
111         GridData groupStructBlocksLData = new GridData();
112         groupStructBlocksLData.grabExcessHorizontalSpace = true;
113         groupStructBlocksLData.grabExcessVerticalSpace = true;
114         groupStructBlocksLData.verticalAlignment = GridData.FILL;
115         groupStructBlocksLData.horizontalAlignment = GridData.FILL;
116         groupStructBlocks.setLayoutData(groupStructBlocksLData);
117         groupStructBlocks.setLayout(groupStructBlocksLayout);
118         groupStructBlocks.setText("struct blocks");
119         
120         blocksTableComposite = new Composite(groupStructBlocks, SWT.NONE);
121         GridLayout blocksTableCompositeLayout = new GridLayout();
122         GridData blocksTableCompositeLData = new GridData();
123         blocksTableCompositeLData.grabExcessVerticalSpace = true;
124         blocksTableCompositeLData.verticalAlignment = GridData.FILL;
125         blocksTableCompositeLData.grabExcessHorizontalSpace = true;
126         blocksTableCompositeLData.horizontalAlignment = GridData.FILL;
127         blocksTableComposite.setLayoutData(blocksTableCompositeLData);
128         blocksTableCompositeLayout.makeColumnsEqualWidth = true;
129         blocksTableComposite.setLayout(blocksTableCompositeLayout);
130         
131         blocksButtonsComposite = new Composite(groupStructBlocks, SWT.NONE);
132         GridLayout blocksButtonsCompositeLayout = new GridLayout();
133         GridData blocksButtonsCompositeLData = new GridData();
134         blocksButtonsCompositeLData.grabExcessVerticalSpace = true;
135         blocksButtonsCompositeLData.verticalAlignment = GridData.FILL;
136         blocksButtonsCompositeLData.horizontalAlignment = GridData.END;
137         blocksButtonsCompositeLData.horizontalIndent = 0;
138 // blocksButtonsCompositeLData.widthHint = 40;
139
blocksButtonsComposite.setLayoutData(blocksButtonsCompositeLData);
140         blocksButtonsCompositeLayout.makeColumnsEqualWidth = true;
141         blocksButtonsComposite.setLayout(blocksButtonsCompositeLayout);
142         blocksButtonsCompositeLayout.horizontalSpacing = 0;
143 // blocksButtonsCompositeLayout.verticalSpacing = 0;
144
blocksButtonsCompositeLayout.marginWidth = 0;
145         blocksButtonsCompositeLayout.marginHeight = 0;
146         
147         buttonBlockUp = new Button(blocksButtonsComposite, SWT.PUSH);
148         buttonBlockUp.setText("Up");
149         GridData buttonLData = new GridData(GridData.FILL_HORIZONTAL);
150         buttonLData.horizontalIndent = 0;
151         buttonLData.horizontalIndent = 0;
152         buttonBlockUp.setLayoutData(buttonLData);
153         buttonBlockUp.addSelectionListener(new SelectionListener() {
154
155             public void widgetSelected(SelectionEvent evt) {
156                 buttonUpPressed(evt);
157             }
158
159             public void widgetDefaultSelected(SelectionEvent arg0) {
160             }
161         });
162         
163         buttonBlockDown = new Button(blocksButtonsComposite, SWT.PUSH);
164         buttonBlockDown.setText("Down");
165         buttonLData = new GridData(GridData.FILL_HORIZONTAL);
166         buttonLData.horizontalIndent = 0;
167         buttonLData.horizontalIndent = 0;
168         buttonBlockDown.setLayoutData(buttonLData);
169         buttonBlockDown.addSelectionListener(new SelectionListener() {
170
171             public void widgetSelected(SelectionEvent evt) {
172                 buttonDownPressed(evt);
173             }
174
175             public void widgetDefaultSelected(SelectionEvent arg0) {
176             }
177         });
178
179         
180         groupStructFields = new Group(this, SWT.NONE);
181         GridLayout groupStructFieldsLayout = new GridLayout();
182         groupStructFieldsLayout.numColumns = 2;
183         groupStructFieldsLayout.horizontalSpacing = 0;
184         groupStructFieldsLayout.verticalSpacing = 0;
185         groupStructFieldsLayout.marginHeight = 0;
186         groupStructFieldsLayout.marginWidth = 0;
187         GridData groupStructFieldsLData = new GridData();
188         groupStructFieldsLData.grabExcessHorizontalSpace = true;
189         groupStructFieldsLData.horizontalAlignment = GridData.FILL;
190         groupStructFieldsLData.grabExcessVerticalSpace = true;
191         groupStructFieldsLData.verticalAlignment = GridData.FILL;
192         groupStructFields.setLayoutData(groupStructFieldsLData);
193         groupStructFields.setLayout(groupStructFieldsLayout);
194         groupStructFields.setText("struct fields");
195         
196         fieldsTableComposite = new Composite(groupStructFields, SWT.NONE);
197         GridLayout fieldsTableCompositeLayout = new GridLayout();
198         GridData fieldsTableCompositeLData = new GridData();
199         fieldsTableCompositeLData.grabExcessVerticalSpace = true;
200         fieldsTableCompositeLData.verticalAlignment = GridData.FILL;
201         fieldsTableCompositeLData.horizontalAlignment = GridData.FILL;
202         fieldsTableCompositeLData.grabExcessHorizontalSpace = true;
203         fieldsTableComposite.setLayoutData(fieldsTableCompositeLData);
204         fieldsTableCompositeLayout.makeColumnsEqualWidth = true;
205         fieldsTableComposite.setLayout(fieldsTableCompositeLayout);
206         
207         fieldsButtonsComposite = new Composite(groupStructFields, SWT.NONE);
208         GridLayout fieldsButtonsCompositeLayout = new GridLayout();
209         GridData fieldsButtonsCompositeLData = new GridData();
210         fieldsButtonsCompositeLData.verticalAlignment = GridData.FILL;
211         fieldsButtonsCompositeLData.grabExcessVerticalSpace = true;
212         fieldsButtonsCompositeLData.horizontalAlignment = GridData.END;
213         fieldsButtonsComposite.setLayoutData(fieldsButtonsCompositeLData);
214         fieldsButtonsCompositeLayout.makeColumnsEqualWidth = true;
215         fieldsButtonsComposite.setLayout(fieldsButtonsCompositeLayout);
216         
217         buttonFieldUp = new Button(fieldsButtonsComposite, SWT.PUSH);
218         buttonFieldUp.setText("Up");
219         buttonLData = new GridData(GridData.FILL_HORIZONTAL);
220         buttonLData.horizontalIndent = 0;
221         buttonLData.horizontalIndent = 0;
222         buttonFieldUp.setLayoutData(buttonLData);
223         
224         buttonFieldDown = new Button(fieldsButtonsComposite, SWT.PUSH);
225         buttonFieldDown.setText("Down");
226         buttonLData = new GridData(GridData.FILL_HORIZONTAL);
227         buttonLData.horizontalIndent = 0;
228         buttonLData.horizontalIndent = 0;
229         buttonFieldDown.setLayoutData(buttonLData);
230         
231         // Blocks table
232
tableViewerBlocks = new TableViewer(blocksTableComposite, SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
233         GridData tgd = new GridData(GridData.FILL_BOTH);
234         Table t = tableViewerBlocks.getTable();
235         t.setHeaderVisible(true);
236         t.setLinesVisible(true);
237         t.setLayoutData(tgd);
238         t.setLayout(new TableLayout());
239         tableViewerBlocks.setContentProvider(new BlockOrderListContentProvider());
240         tableViewerBlocks.setLabelProvider(new BlockOrderListLabelProvider());
241         new TableColumn(t, SWT.LEFT, 0).setText(IpanemaBasePlugin.getResourceString("person.preferences.pages.PersonStructOrder.blockstable.col0"));
242         tableViewerBlocks.setInput(
243                 PersonStructOrderConfigModule.getSharedInstance()
244                 .structBlockDisplayOrder()
245         );
246         
247         
248         // Fields table
249
tableViewerFields = new TableViewer(fieldsTableComposite, SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
250         tgd = new GridData(GridData.FILL_BOTH);
251         t = tableViewerFields.getTable();
252         t.setHeaderVisible(true);
253         t.setLinesVisible(true);
254         t.setLayoutData(tgd);
255         t.setLayout(new TableLayout());
256         new TableColumn(t, SWT.LEFT, 0).setText(IpanemaBasePlugin.getResourceString("person.preferences.pages.PersonStructOrder.fieldstable.col0"));
257         
258         this.layout();
259     }
260     
261     
262     protected void buttonUpPressed(SelectionEvent evt) {
263         if (evt.getSource().equals(buttonBlockUp)) {
264             tableViewerBlocks.getElementAt(0);
265             IStructuredSelection selection = (IStructuredSelection)tableViewerBlocks.getSelection();
266             if (!selection.isEmpty()) {
267                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc)selection.getFirstElement();
268                 int priority = ((Integer JavaDoc)entry.getValue()).intValue();
269     // tableViewerBlocks.getSelection();
270
((BlockOrderListContentProvider)tableViewerBlocks.getContentProvider()).moveUp(priority);
271                 tableViewerBlocks.refresh();
272     // tableViewerBlocks.getContentProvider().
273
// tableViewerBlocks.
274
}
275         }
276     }
277     
278     protected void buttonDownPressed(SelectionEvent evt) {
279         if (evt.getSource().equals(buttonBlockDown)) {
280             tableViewerBlocks.getElementAt(0);
281             IStructuredSelection selection = (IStructuredSelection)tableViewerBlocks.getSelection();
282             if (!selection.isEmpty()) {
283                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc)selection.getFirstElement();
284                 int priority = ((Integer JavaDoc)entry.getValue()).intValue();
285     // tableViewerBlocks.getSelection();
286
((BlockOrderListContentProvider)tableViewerBlocks.getContentProvider()).moveDown(priority);
287                 tableViewerBlocks.refresh();
288     // tableViewerBlocks.getContentProvider().
289
// tableViewerBlocks.
290
}
291         }
292     }
293     
294     /**
295      *
296      */

297     public Map JavaDoc getStructBlockOrder() {
298         return ((BlockOrderListContentProvider)tableViewerBlocks.getContentProvider()).getStructBlockOrder();
299     }
300 }
301
Popular Tags