Skip to content

Package: TreeMasterDetailSWTBuilder$2

TreeMasterDetailSWTBuilder$2

nameinstructionbranchcomplexitylinemethod
dispose()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getLabelProvider()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.swt.treemasterdetail;
15:
16: import java.util.Collection;
17:
18: import org.eclipse.emfforms.common.Optional;
19: import org.eclipse.emfforms.internal.swt.treemasterdetail.DefaultTreeMasterDetailCustomization;
20: import org.eclipse.emfforms.spi.swt.treemasterdetail.actions.MasterDetailAction;
21: import org.eclipse.emfforms.spi.swt.treemasterdetail.util.CreateElementCallback;
22: import org.eclipse.jface.viewers.IBaseLabelProvider;
23: import org.eclipse.jface.viewers.IContentProvider;
24: import org.eclipse.jface.viewers.ILabelDecorator;
25: import org.eclipse.jface.viewers.TreeViewer;
26: import org.eclipse.jface.viewers.ViewerFilter;
27: import org.eclipse.swt.widgets.Composite;
28:
29: /**
30: * The TreeMasterDetailSWTBuilder is initialized with a default behaviour. It offers methods to customize certain
31: * aspects of the tree master detail.
32: *
33: * @author Johannes Faltermeier
34: *
35: */
36: public final class TreeMasterDetailSWTBuilder {
37:
38:         private final Composite composite;
39:         private final int swtStyleBits;
40:         private final Object input;
41:         private final DefaultTreeMasterDetailCustomization behaviour;
42:
43:         private int renderDelay;
44:
45:         /**
46:          * Default constructor.
47:          *
48:          * @param composite the parent composite
49:          * @param swtStyleBits the style bits for the tree master detail composite
50:          * @param input the input object
51:          */
52:         /* package */ TreeMasterDetailSWTBuilder(Composite composite, int swtStyleBits, Object input) {
53:                 this.composite = composite;
54:                 this.swtStyleBits = swtStyleBits;
55:                 this.input = input;
56:                 behaviour = new DefaultTreeMasterDetailCustomization();
57:                 renderDelay = 100;
58:         }
59:
60:         /**
61:          * Use this method to set a custom {@link org.eclipse.jface.viewers.IContentProvider IContentProvider} on the tree
62:          * viewer. The default implementation will use
63:          * an {@link org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider AdapterFactoryContentProvider}.
64:          *
65:          * @param contentProvider the desired behavior
66:          * @return self
67:          */
68:         public TreeMasterDetailSWTBuilder customizeContentProvider(ContentProviderProvider contentProvider) {
69:                 behaviour.setContentProvider(contentProvider);
70:                 return this;
71:         }
72:
73:         /**
74:          * Use this method to set a custom {@link org.eclipse.jface.viewers.IContentProvider IContentProvider} on the tree
75:          * viewer. If the content provider requires more dispose code than calling {@link IContentProvider#dispose()} use
76:          * {@link #customizeContentProvider(ContentProviderProvider)} instead. The default implementation will use
77:          * an {@link org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider AdapterFactoryContentProvider}.
78:          *
79:          * @param contentProvider the content provider to add
80:          * @return self
81:          */
82:         public TreeMasterDetailSWTBuilder customizeContentProvider(final IContentProvider contentProvider) {
83:                 behaviour.setContentProvider(new ContentProviderProvider() {
84:
85:                         @Override
86:                         public void dispose() {
87:                                 contentProvider.dispose();
88:                         }
89:
90:                         @Override
91:                         public IContentProvider getContentProvider() {
92:                                 return contentProvider;
93:                         }
94:                 });
95:                 return this;
96:         }
97:
98:         /**
99:          * Use this method to create the parent composite, which will contain the detail composite. The default
100:          * implementation will create a {@link org.eclipse.swt.custom.ScrolledComposite ScrolledComposite} which allows
101:          * vertical and horizontal scrolling.
102:          *
103:          * @param detailComposite the desired behavior
104:          * @return self
105:          */
106:         public TreeMasterDetailSWTBuilder customizeDetailComposite(DetailCompositeBuilder detailComposite) {
107:                 behaviour.setDetailComposite(detailComposite);
108:                 return this;
109:         }
110:
111:         /**
112:          * Use this method to add a customized drag and drop behaviour to the tree or to remove drag and drop functionality.
113:          * The default implementation supports {@link org.eclipse.swt.dnd.DND#DROP_COPY DND#DROP_COPY},
114:          * {@link org.eclipse.swt.dnd.DND#DROP_MOVE DND#DROP_MOVE} and {@link org.eclipse.swt.dnd.DND#DROP_LINK
115:          * DND#DROP_LINK} based
116:          * on EMF Edit.
117:          *
118:          * @param dnd the desired behavior
119:          * @return self
120:          */
121:         public TreeMasterDetailSWTBuilder customizeDragAndDrop(DNDProvider dnd) {
122:                 behaviour.setDragAndDrop(dnd);
123:                 return this;
124:         }
125:
126:         /**
127:          * Use this method a add a custom {@link org.eclipse.jface.viewers.IBaseLabelProvider IBaseLabelProvider} to the
128:          * tree. The default implementation uses an
129:          * {@link org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider AdapterFactoryLabelProvider}.
130:          *
131:          * @param provider the desired behavior
132:          * @return self
133:          */
134:         public TreeMasterDetailSWTBuilder customizeLabelProvider(LabelProviderProvider provider) {
135:                 behaviour.setLabelProvider(provider);
136:                 return this;
137:         }
138:
139:         /**
140:          * Use this method a add a custom {@link org.eclipse.jface.viewers.IBaseLabelProvider IBaseLabelProvider} to the
141:          * tree. If the label provider requires more dispose code than a call to {@link IBaseLabelProvider#dispose()} use
142:          * {@link #customizeLabelProvider(LabelProviderProvider)} instead. The default implementation uses an
143:          * {@link org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider AdapterFactoryLabelProvider}.
144:          *
145:          * @param provider the label provider to add
146:          * @return self
147:          */
148:         public TreeMasterDetailSWTBuilder customizeLabelProvider(final IBaseLabelProvider provider) {
149:                 behaviour.setLabelProvider(new LabelProviderProvider() {
150:
151:                         @Override
152:                         public void dispose() {
153:                                 provider.dispose();
154:                         }
155:
156:                         @Override
157:                         public IBaseLabelProvider getLabelProvider() {
158:                                 return provider;
159:                         }
160:                 });
161:                 return this;
162:         }
163:
164:         /**
165:          * Use this method to add a {@link ILabelDecorator} for decorating the labels of the label provider. The default
166:          * implementation does not use a decorator.
167:          *
168:          * @param provider the {@link LabelDecoratorProvider} which will be used to create the decorator
169:          * @return self
170:          * @since 1.9
171:          */
172:         public TreeMasterDetailSWTBuilder customizeLabelDecorator(LabelDecoratorProvider provider) {
173:                 behaviour.setLabelDecorator(provider);
174:                 return this;
175:         }
176:
177:         /**
178:          * Use this method to add a {@link ILabelDecorator} for decorating the labels of the label provider. The default
179:          * implementation does not use a decorator.
180:          *
181:          * @param decorator the decorator instance to be used
182:          * @return self
183:          * @since 1.9
184:          */
185:         public TreeMasterDetailSWTBuilder customizeLabelDecorator(final ILabelDecorator decorator) {
186:                 behaviour.setLabelDecorator(new LabelDecoratorProvider() {
187:                         @Override
188:                         public Optional<ILabelDecorator> getLabelDecorator(TreeViewer viewer) {
189:                                 return Optional.of(decorator);
190:                         }
191:
192:                         @Override
193:                         public void dispose() {
194:                                 /* no op */
195:                         }
196:                 });
197:                 return this;
198:         }
199:
200:         /**
201:          * Use this method to customize the {@link org.eclipse.swt.widgets.Menu Menu} which is shown when an element in the
202:          * tree is right-clicked. The
203:          * default implementation will offer menu entries to create new elements based on EMF Edit and to delete elements.
204:          *
205:          * @param menu the desired behavior
206:          * @return self
207:          */
208:         public TreeMasterDetailSWTBuilder customizeMenu(MenuProvider menu) {
209:                 behaviour.setMenu(menu);
210:                 return this;
211:         }
212:
213:         /**
214:          * Use this method to customize the {@link org.eclipse.swt.widgets.Menu Menu} which is shown when an element in the
215:          * tree is right-clicked. Use this method to add additional menu entries.
216:          *
217:          * @param rightClickActions the additional right click actions which will be shown in the context menu
218:          * @return self
219:          * @since 1.8
220:          */
221:         public TreeMasterDetailSWTBuilder customizeMenuItems(Collection<MasterDetailAction> rightClickActions) {
222:                 behaviour.customizeMenu(rightClickActions);
223:                 return this;
224:         }
225:
226:         /**
227:          * Use this method to customize the {@link org.eclipse.swt.widgets.Menu Menu} which is shown when an element in the
228:          * tree is right-clicked. Use this method to influence the way new children are created.
229:          *
230:          * @param createElementCallback a callback which gets notified when a new child is created. this allows to veto the
231:          * creation or to change the object to be added
232:          * @return self
233:          * @since 1.8
234:          */
235:         public TreeMasterDetailSWTBuilder customizeCildCreation(CreateElementCallback createElementCallback) {
236:                 behaviour.customizeMenu(createElementCallback);
237:                 return this;
238:         }
239:
240:         /**
241:          * Use this method to customize the {@link org.eclipse.swt.widgets.Menu Menu} which is shown when an element in the
242:          * tree is right-clicked. Use this method to change the way elements are deleted.
243:          *
244:          * @param deleteActionBuilder the delete action which will be added to the context menu
245:          * @return self
246:          * @since 1.8
247:          */
248:         public TreeMasterDetailSWTBuilder customizeDelete(DeleteActionBuilder deleteActionBuilder) {
249:                 behaviour.customizeMenu(deleteActionBuilder);
250:                 return this;
251:         }
252:
253:         /**
254:          * Use this method to customize which element should be selected after the initial rendering. The default bahviour
255:          * is to select the root node, if it is displayed in the tree.
256:          *
257:          * @param selection the desired behavior
258:          * @return self
259:          */
260:         public TreeMasterDetailSWTBuilder customizeInitialSelection(InitialSelectionProvider selection) {
261:                 behaviour.setInitialSelection(selection);
262:                 return this;
263:         }
264:
265:         /**
266:          * Use this method to create the {@link org.eclipse.jface.viewers.TreeViewer TreeViewer} which is part of the tree
267:          * master detail. The default
268:          * implementation creates a regular {@link org.eclipse.jface.viewers.TreeViewer TreeViewer} with an
269:          * {@link org.eclipse.jface.viewers.TreeViewer#setAutoExpandLevel(int) expand
270:          * level} of 3.
271:          *
272:          * @param tree the desired behavior
273:          * @return self
274:          */
275:         public TreeMasterDetailSWTBuilder customizeTree(TreeViewerBuilder tree) {
276:                 behaviour.setTree(tree);
277:                 return this;
278:         }
279:
280:         /**
281:          * Use this method to influence the width of the composite which hosts the
282:          * {@link org.eclipse.jface.viewers.TreeViewer TreeViewer}. The default is 300px.
283:          *
284:          * @param width the desired width
285:          * @return self
286:          */
287:         public TreeMasterDetailSWTBuilder customizeInitialTreeWidth(final int width) {
288:                 behaviour.setInitialTreeWidth(new TreeWidthProvider() {
289:                         @Override
290:                         public int getInitialTreeWidth() {
291:                                 return width;
292:                         }
293:                 });
294:                 return this;
295:         }
296:
297:         /**
298:          * Use this method to add {@link org.eclipse.jface.viewers.ViewerFilter ViewerFilters} on the tree. The default
299:          * implementation does not add
300:          * filters.
301:          *
302:          * @param filters the filters to add
303:          * @return self
304:          */
305:         public TreeMasterDetailSWTBuilder customizeViewerFilters(final ViewerFilter[] filters) {
306:                 behaviour.setViewerFilters(new ViewerFilterProvider() {
307:                         @Override
308:                         public ViewerFilter[] getViewerFilters() {
309:                                 return filters;
310:                         }
311:                 });
312:                 return this;
313:         }
314:
315:         /**
316:          * Use this method to specify which {@link org.eclipse.emf.ecp.view.spi.context.ViewModelService ViewModelServices}
317:          * will be added when the detail views
318:          * are rendered. The default implementation does not add any services.
319:          *
320:          * @param viewServiceProvider the desired behavior
321:          * @return self
322:          */
323:         public TreeMasterDetailSWTBuilder customizeViewModelServices(ViewModelServiceProvider viewServiceProvider) {
324:                 behaviour.setViewModelServices(viewServiceProvider);
325:                 return this;
326:         }
327:
328:         /**
329:          * Use this method to specify the time between a detected selection change and updating the detail panel. The
330:          * default is 100ms.
331:          *
332:          * @param updateDelay the new update delay in ms
333:          * @return self
334:          * @since 1.11
335:          */
336:         public TreeMasterDetailSWTBuilder customizeUpdateDelay(int updateDelay) {
337:                 renderDelay = updateDelay;
338:                 return this;
339:         }
340:
341:         /**
342:          * Use this method to specify whether the tree and its details should be rendered as read-only. The default is
343:          * false. Setting the tree master detail as read-only has the following implications:
344:          * <ul>
345:          * <li>Set all detail views as read-only</li>
346:          * <li>Disable the tree's context menu</li>
347:          * <li>Deactivate drag and drop in the tree</li>
348:          * </ul>
349:          * <strong>Note:</strong> Setting this to true voids all menu and DND customizations.
350:          *
351:          * @param readOnly <code>true</code> to make the tree master detail read-only.
352:          * @return self
353:          * @since 1.22
354:          */
355:         public TreeMasterDetailSWTBuilder customizeReadOnly(boolean readOnly) {
356:                 behaviour.setReadOnly(readOnly);
357:                 return this;
358:         }
359:
360:         /**
361:          * Call this method after all desired customizations have been passed to the builder. The will create a new
362:          * {@link TreeMasterDetailComposite} with the desired customizations.
363:          *
364:          * @return the {@link TreeMasterDetailComposite}
365:          */
366:         public TreeMasterDetailComposite create() {
367:                 return new TreeMasterDetailComposite(composite, swtStyleBits, input, behaviour, renderDelay);
368:         }
369:
370: }