1
23package org.jzuul.gdk.swt;
24
25import java.util.ArrayList;
26import java.util.Arrays;
27import java.util.Iterator;
28
29import org.eclipse.swt.SWT;
30import org.eclipse.swt.events.SelectionEvent;
31import org.eclipse.swt.events.SelectionListener;
32import org.eclipse.swt.layout.GridData;
33import org.eclipse.swt.layout.GridLayout;
34import org.eclipse.swt.widgets.Button;
35import org.eclipse.swt.widgets.Composite;
36import org.eclipse.swt.widgets.Group;
37import org.eclipse.swt.widgets.Label;
38import org.eclipse.swt.widgets.MessageBox;
39import org.eclipse.swt.widgets.Shell;
40import org.eclipse.swt.widgets.Text;
41import org.jdom.Content;
42import org.jdom.Element;
43import org.jdom.Parent;
44
45
52public class ItemDetailsComposite extends Composite {
53
54 protected Text description;
55
56 protected PropertyComposite properties;
57
58 protected Element item;
59
60 private Button bt2;
61
62 private Button bt1;
63
64
68 public ItemDetailsComposite(Composite arg0, int arg1) {
69 super(arg0, arg1);
70
71 GridData layoutGridData = new GridData(GridData.FILL_BOTH);
73 layoutGridData.horizontalSpan = 4;
74 this.setLayoutData(layoutGridData);
75 GridLayout layout = new GridLayout(1, false);
76 this.setLayout(layout);
77
78 final Group group = new Group(this, SWT.NONE);
80 GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
81 group.setLayoutData(gridData);
82 GridLayout groupLayout = new GridLayout(2, false);
83 group.setLayout(groupLayout);
84
85 new Label((Composite) group, SWT.NONE).setText(Messages.getString("DESCRIPTION_COLON")); description = new Text((Composite) group, SWT.BORDER);
87 description.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
88
89 properties = new PropertyComposite((Composite) this, SWT.NONE);
90
91
93 final Group buttonGroup = new Group(this, SWT.NONE);
94 GridData buttonGridData = new GridData(GridData.FILL_HORIZONTAL);
95 buttonGridData.horizontalSpan = 1;
96 buttonGroup.setLayoutData(buttonGridData);
97 GridLayout buttonGroupLayout = new GridLayout(2, false);
98 buttonGroup.setLayout(buttonGroupLayout);
99
00 bt2 = new Button((Composite) buttonGroup, SWT.NONE);
01 bt2.setText(Messages.getString("EDIT_EVENTS")); bt2.addSelectionListener(new SelectionListener() {
03
04 public void widgetSelected(SelectionEvent arg0) {
05 java.util.List events = item.getChildren("event"); EventEditorDialog ed = new EventEditorDialog(new Shell(arg0.display));
07 ed.open(events);
08
09 }
10
11 public void widgetDefaultSelected(SelectionEvent arg0) {}
12 });
13
14 bt1 = new Button((Composite) buttonGroup, SWT.NONE);
15 bt1.setText(Messages.getString("EDIT_COMBINATIONS")); bt1.addSelectionListener(new SelectionListener() {
17
18 public void widgetSelected(SelectionEvent arg0) {
19 String[] items = getItemNames();
20 if (items != null && items.length > 1) {
21 CombinationEditorDialog ce = new CombinationEditorDialog(new Shell(arg0.display));
22 ce.open(item, items);
23 } else {
24 MessageBox mb = new MessageBox(new Shell(arg0.display), SWT.ICON_ERROR);
25 mb.setMessage(Messages.getString("COMB_ERROR_MSG")); mb.open();
27 return;
28 }
29
30 }
31
32 public void widgetDefaultSelected(SelectionEvent arg0) {}
33 });
34
35 group.layout();
36 }
37
38 public void showItemElement(Element item) {
39 cleanUpChanges();
40 this.item = item;
41 if (item == null) {
42 this.clear();
43 this.disable();
44 return;
45 }
46 this.enable();
47 if (item.getChildText("description") != null && !item.getChildText("description").equals("")) { description.setText(item.getChildText("description")); } else {
50 description.setText(""); description.setFocus();
52 }
53 properties.showProperties(item.getChildren("property"));
55 }
56
57 public void cleanUpChanges() {
58 if (item == null) return;
59 item.removeChildren("property"); item.addContent(properties.getElementList());
61 Element descr = item.getChild("description"); descr.setText(description.getText());
63
64 }
65
66 protected String[] getItemNames() {
67 if (item == null) return null;
68 java.util.List names = new ArrayList();
69
70 Parent p = item.getParent();
71 java.util.List contents = p.getContent();
72
73 for (Iterator contentIter = contents.iterator(); contentIter.hasNext();) {
74 Content contentElement = (Content) contentIter.next();
75 if (contentElement instanceof Element) {
76 String name = ((Element) contentElement).getAttributeValue("name"); System.err.println("Found new Element: " + name); names.add(name);
79 }
80 }
81 String[] retval = new String[names.size()];
82 names.toArray(retval);
83 Arrays.sort(retval);
84 return retval;
85 }
86
87 protected void clear() {
88 description.setText(""); item = null;
90 properties.showProperties(null);
91 }
92
93 public void disable() {
94 setEnabled(false);
95 }
96
97 public void enable() {
98 setEnabled(true);
99 }
00
01 public void setEnabled(boolean enabled) {
02 bt1.setEnabled(enabled);
03 bt2.setEnabled(enabled);
04 description.setEnabled(enabled);
05 }
06
07}