001: package org.terracotta.dso.views;
002:
003: import org.eclipse.jface.action.IMenuListener;
004: import org.eclipse.jface.action.MenuManager;
005: import org.eclipse.jface.viewers.ISelectionProvider;
006: import org.eclipse.jface.viewers.TreeViewer;
007: import org.eclipse.swt.SWT;
008: import org.eclipse.swt.events.KeyListener;
009: import org.eclipse.swt.layout.GridData;
010: import org.eclipse.swt.widgets.Composite;
011: import org.eclipse.swt.widgets.Menu;
012: import org.eclipse.swt.widgets.Tree;
013: import org.eclipse.ui.IWorkbenchPartSite;
014: import org.terracotta.dso.TcPlugin;
015:
016: import com.terracottatech.config.TcConfigDocument.TcConfig;
017:
018: class ConfigViewer extends TreeViewer {
019: private ConfigViewPart fPart;
020: private ConfigContentProvider fContentProvider;
021:
022: ConfigViewer(Composite parent, ConfigViewPart part) {
023: super (new Tree(parent, SWT.MULTI));
024:
025: fPart = part;
026:
027: getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
028: setUseHashlookup(true);
029: setAutoExpandLevel(ALL_LEVELS);
030: fContentProvider = new ConfigContentProvider();
031: setContentProvider(fContentProvider);
032: setLabelProvider(new ConfigLabelProvider(this ));
033:
034: clearViewer();
035: }
036:
037: void setConfig(TcConfig config) {
038: if (config != null && config != TcPlugin.BAD_CONFIG) {
039: setInput(getTreeRoot(config));
040: } else {
041: clearViewer();
042: }
043: }
044:
045: ConfigViewPart getPart() {
046: return fPart;
047: }
048:
049: void setFocus() {
050: getControl().setFocus();
051: }
052:
053: boolean isInFocus() {
054: return getControl().isFocusControl();
055: }
056:
057: void addKeyListener(KeyListener keyListener) {
058: getControl().addKeyListener(keyListener);
059: }
060:
061: private TreeRoot getTreeRoot(TcConfig root) {
062: return new TreeRoot(root);
063: }
064:
065: void initContextMenu(IMenuListener menuListener,
066: IWorkbenchPartSite viewSite,
067: ISelectionProvider selectionProvider) {
068: MenuManager menuMgr = new MenuManager();
069: menuMgr.setRemoveAllWhenShown(true);
070: menuMgr.addMenuListener(menuListener);
071: Menu menu = menuMgr.createContextMenu(getTree());
072: getTree().setMenu(menu);
073: viewSite.registerContextMenu(menuMgr, selectionProvider);
074: }
075:
076: void refreshRoots() {
077: refresh(fContentProvider.rootsWrapper);
078: expandToLevel(fContentProvider.rootsWrapper, ALL_LEVELS);
079: }
080:
081: void refreshRoot(int index) {
082: if (fContentProvider.rootsWrapper != null) {
083: RootWrapper wrapper = fContentProvider.rootsWrapper
084: .getChildAt(index);
085: if (wrapper != null) {
086: refresh(wrapper);
087: }
088: }
089: }
090:
091: void refreshDistributedMethods() {
092: refresh(fContentProvider.distributedMethodsWrapper);
093: expandToLevel(fContentProvider.distributedMethodsWrapper,
094: ALL_LEVELS);
095: }
096:
097: void refreshDistributedMethod(int index) {
098: if (fContentProvider.distributedMethodsWrapper != null) {
099: DistributedMethodWrapper wrapper = fContentProvider.distributedMethodsWrapper
100: .getChildAt(index);
101: if (wrapper != null) {
102: refresh(wrapper);
103: }
104: }
105: }
106:
107: void refreshBootClasses() {
108: refresh(fContentProvider.additionalBootJarClassesWrapper);
109: expandToLevel(fContentProvider.additionalBootJarClassesWrapper,
110: ALL_LEVELS);
111: }
112:
113: void refreshBootClass(int index) {
114: if (fContentProvider.additionalBootJarClassesWrapper != null) {
115: BootClassWrapper wrapper = fContentProvider.additionalBootJarClassesWrapper
116: .getChildAt(index);
117: if (wrapper != null) {
118: refresh(wrapper);
119: }
120: }
121: }
122:
123: void refreshTransientFields() {
124: refresh(fContentProvider.transientFieldsWrapper);
125: expandToLevel(fContentProvider.transientFieldsWrapper,
126: ALL_LEVELS);
127: }
128:
129: void refreshTransientField(int index) {
130: if (fContentProvider.transientFieldsWrapper != null) {
131: TransientFieldWrapper wrapper = fContentProvider.transientFieldsWrapper
132: .getChildAt(index);
133: if (wrapper != null) {
134: refresh(wrapper);
135: }
136: }
137: }
138:
139: void refreshNamedLock(int index) {
140: if (fContentProvider.namedLocksWrapper != null) {
141: NamedLockWrapper wrapper = fContentProvider.namedLocksWrapper
142: .getChildAt(index);
143: if (wrapper != null) {
144: refresh(wrapper);
145: }
146: }
147: }
148:
149: void refreshNamedLocks() {
150: if (fContentProvider.namedLocksWrapper != null) {
151: refresh(fContentProvider.namedLocksWrapper);
152: expandToLevel(fContentProvider.namedLocksWrapper,
153: ALL_LEVELS);
154: }
155: }
156:
157: void refreshAutolock(int index) {
158: if (fContentProvider.autolocksWrapper != null) {
159: AutolockWrapper wrapper = fContentProvider.autolocksWrapper
160: .getChildAt(index);
161: if (wrapper != null) {
162: refresh(wrapper);
163: }
164: }
165: }
166:
167: void refreshAutolocks() {
168: if (fContentProvider.autolocksWrapper != null) {
169: refresh(fContentProvider.locksWrapper);
170: expandToLevel(fContentProvider.locksWrapper, ALL_LEVELS);
171: }
172: }
173:
174: void refreshIncludeRule(int index) {
175: if (fContentProvider.includesWrapper != null) {
176: IncludeWrapper wrapper = fContentProvider.includesWrapper
177: .getChildAt(index);
178: if (wrapper != null) {
179: refresh(wrapper);
180: }
181: }
182: }
183:
184: void refreshIncludeRules() {
185: if (fContentProvider.includesWrapper != null) {
186: refresh(fContentProvider.includesWrapper);
187: expandToLevel(fContentProvider.includesWrapper, ALL_LEVELS);
188: }
189: }
190:
191: void refreshExcludeRule(int index) {
192: if (fContentProvider.excludesWrapper != null) {
193: ExcludeWrapper wrapper = fContentProvider.excludesWrapper
194: .getChildAt(index);
195: if (wrapper != null) {
196: refresh(wrapper);
197: }
198: }
199: }
200:
201: void refreshExcludeRules() {
202: if (fContentProvider.excludesWrapper != null) {
203: refresh(fContentProvider.excludesWrapper);
204: expandToLevel(fContentProvider.excludesWrapper, ALL_LEVELS);
205: }
206: }
207:
208: void refreshInstrumentationRules() {
209: refresh(fContentProvider.instrumentedClassesWrapper);
210: expandToLevel(fContentProvider.instrumentedClassesWrapper,
211: ALL_LEVELS);
212: }
213:
214: void clearViewer() {
215: setInput(TreeRoot.EMPTY_ROOT);
216: }
217: }
|