001: package net.sourceforge.tracelog.ui;
002:
003: import net.sourceforge.tracelog.listeners.GenericListener;
004: import net.sourceforge.tracelog.utils.Util;
005:
006: import org.eclipse.jface.viewers.ISelectionChangedListener;
007: import org.eclipse.jface.viewers.IStructuredSelection;
008: import org.eclipse.jface.viewers.ITreeContentProvider;
009: import org.eclipse.jface.viewers.SelectionChangedEvent;
010: import org.eclipse.jface.viewers.TreeViewer;
011: import org.eclipse.jface.viewers.Viewer;
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.events.MouseEvent;
014: import org.eclipse.swt.graphics.Image;
015: import org.eclipse.swt.layout.GridData;
016: import org.eclipse.swt.layout.GridLayout;
017: import org.eclipse.swt.widgets.Button;
018: import org.eclipse.swt.widgets.Composite;
019: import org.eclipse.swt.widgets.Control;
020: import org.eclipse.swt.widgets.Shell;
021:
022: public class ShellOption extends AbstractWidget {
023: // private Logger log = Logger.getLogger(ShellOption.class);
024:
025: private Composite buttonComposite;
026: private Composite categoryComposite;
027: private Composite contentComposite;
028: private GridLayout defaultGL;
029: private Composite frameComposite;
030: private ShellOptionMenu optionMenu;
031: private Shell optionShell;
032:
033: /**
034: * Package-access constructor.
035: */
036: ShellOption() {
037: super ();
038: this .optionShell = null;
039:
040: defaultGL = new GridLayout();
041: defaultGL.horizontalSpacing = 0;
042: defaultGL.verticalSpacing = 0;
043: defaultGL.marginHeight = 0;
044: defaultGL.marginWidth = 0;
045: }
046:
047: public void run() {
048: optionShell = new Shell(parentShell, SWT.SHELL_TRIM
049: | SWT.SYSTEM_MODAL);
050: optionShell.setImage(new Image(display, Util
051: .getOwnResource(projectProperties.getShellIconPath())));
052: optionShell.setLayout(defaultGL);
053: optionShell.setText("Options");
054: optionShell.setMinimumSize(800, 600);
055:
056: frameComposite = new Composite(optionShell, SWT.NONE);
057: frameComposite.setLayout(new GridLayout(2, false));
058: frameComposite.setLayoutData(UIUtil.getGridDataFillBoth());
059:
060: categoryComposite = new Composite(frameComposite, SWT.BORDER);
061: categoryComposite.setLayout(defaultGL);
062: GridData categoryGD = UIUtil.getGridDataFillVertical();
063: categoryGD.widthHint = 150;
064: categoryComposite.setLayoutData(categoryGD);
065: categoryComposite.setBackground(UIUtil.getColorWhite());
066:
067: contentComposite = new Composite(frameComposite, SWT.NONE);
068: contentComposite.setLayout(defaultGL);
069: contentComposite.setLayoutData(UIUtil.getGridDataFillBoth());
070:
071: GridData buttonGD = new GridData(GridData.FILL_HORIZONTAL
072: | GridData.HORIZONTAL_ALIGN_END);
073: buttonGD.horizontalSpan = 2;
074:
075: buttonComposite = new Composite(frameComposite, SWT.NONE);
076: buttonComposite.setLayout(defaultGL);
077: buttonComposite.setLayoutData(buttonGD);
078:
079: setupMenu();
080: setupCategoryList();
081: setupButton();
082:
083: optionMenu.getChildren()[0].showContent();
084:
085: UIUtil.centerAlignedShell(parentShell, optionShell);
086: optionShell.open();
087: optionShell.layout();
088: }
089:
090: private void clearContent() {
091: for (Control control : contentComposite.getChildren()) {
092: control.dispose();
093: }
094: }
095:
096: private void setupButton() {
097: Button closeBtn = new Button(buttonComposite, SWT.PUSH);
098: closeBtn.setText("Close");
099: GridData gd = UIUtil.getGridDataFillHorizontal();
100: gd.minimumWidth = 100;
101:
102: closeBtn.setLayoutData(gd);
103:
104: closeBtn.addMouseListener(new GenericListener() {
105: public void mouseUp(MouseEvent e) {
106: optionShell.dispose();
107: }
108: });
109: }
110:
111: private void setupCategoryList() {
112: final TreeViewer treeViewer = new TreeViewer(categoryComposite,
113: SWT.NONE);
114: treeViewer.getTree().setLayout(new GridLayout());
115: treeViewer.getTree().setLayoutData(
116: new GridData(GridData.FILL_BOTH));
117: treeViewer
118: .addSelectionChangedListener(new ISelectionChangedListener() {
119: public void selectionChanged(
120: SelectionChangedEvent event) {
121: if (event.getSelection() instanceof IStructuredSelection) {
122: clearContent();
123:
124: IStructuredSelection structuredSelection = (IStructuredSelection) event
125: .getSelection();
126: ((ShellOptionMenu) structuredSelection
127: .getFirstElement()).showContent();
128: }
129: }
130: });
131:
132: treeViewer.setContentProvider(new ITreeContentProvider() {
133: public void dispose() {
134: }
135:
136: public Object[] getChildren(Object arg0) {
137: return ((ShellOptionMenu) arg0).getChildren();
138: }
139:
140: public Object[] getElements(Object arg0) {
141: return optionMenu.getChildren();
142: }
143:
144: public Object getParent(Object arg0) {
145: return ((ShellOptionMenu) arg0).getParent();
146: }
147:
148: public boolean hasChildren(Object arg0) {
149: return ((ShellOptionMenu) arg0).hasChildren();
150: }
151:
152: public void inputChanged(Viewer arg0, Object arg1,
153: Object arg2) {
154: }
155: });
156:
157: treeViewer.setInput("root");
158: treeViewer.expandAll();
159: }
160:
161: private void setupMenu() {
162: optionMenu = new ShellOptionMenu("Root", null);
163:
164: optionMenu.addChild(new ShellOptionMenu("General",
165: widgetFactory.createOptionShellGeneral(optionShell,
166: contentComposite, mediator)));
167:
168: ShellOptionMenu logConfig = new ShellOptionMenu(
169: "Log Configuration", null);
170: logConfig.addChild(new ShellOptionMenu("Log Groups",
171: widgetFactory.createOptionShellLogGroup(optionShell,
172: contentComposite, mediator)));
173: logConfig.addChild(new ShellOptionMenu("Log Files",
174: widgetFactory.createOptionShellLogFile(optionShell,
175: contentComposite, mediator)));
176:
177: optionMenu.addChild(logConfig);
178: }
179: }
|