Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 11fb06c9481a35408caf37b7977cb90b04b040c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
/*******************************************************************************
 * Copyright (c) 2009, 2010, 2012 Mia-Software.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Nicolas Bros (Mia-Software) - initial API and implementation
 *     Vincent Lorenzo (CEA-LIST) - Bug 341328 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
 *     Gregoire Dupe (Mia-Software) - Bug 369987 - [Restructuring][Table] Switch to the new customization and facet framework
 *     Gregoire Dupe (Mia-Software) - Bug 373078 - API Cleaning
 *******************************************************************************/
package org.eclipse.emf.facet.custom.ui.internal.dialog;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
import org.eclipse.emf.facet.custom.ui.internal.Messages;
import org.eclipse.emf.facet.custom.ui.internal.exported.dialog.ILoadCustomizationsDialog;
import org.eclipse.emf.facet.custom.ui.internal.exported.exception.IllegalParameterException;
import org.eclipse.emf.facet.util.ui.internal.exported.dialog.IDialogCallback;
import org.eclipse.emf.facet.util.ui.internal.exported.dialog.IDialogCallbackWithPreCommit;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.dialogs.PatternFilter;

public class LoadCustomizationsDialog<D> extends Dialog implements
		ILoadCustomizationsDialog<D> {

	private static final int TREE_WIDTH = 300;
	private static final int TREE_HEIGHT = 250;
	private static final int NUM_COLUMNS = 4;
	private final List<Customization> availableCustoms;
	private final LabelProvider labelProvider;
	private final IContentProvider contentProvider = new ITreeContentProvider() {

		public Object[] getElements(final Object inputElement) {
			@SuppressWarnings("unchecked")
			final List<Customization> customizations = (List<Customization>) inputElement;
			return customizations.toArray();
		}

		public void inputChanged(final Viewer viewer, final Object oldInput,
				final Object newInput) {
			// nothing
		}

		public void dispose() {
			// nothing
		}

		public Object[] getChildren(final Object parentElement) {
			return new Object[]{};
		}

		public Object getParent(final Object element) {
			return null;
		}

		public boolean hasChildren(final Object element) {
			return false;
		}
	};
	private final EList<Customization> selectedCustomizations;
	private TreeViewer availableCustomizationsTreeViewer;
	private TreeViewer selectedCustomizationsTreeViewer;
	private Button addButton;
	private Button removeButton;
	private Button addAllButton;
	private Button removeAllButton;
	private Button upButton;
	private Button downButton;
	private Button loadRequiredFacetsCheckbox;
	private boolean loadRequiredFacetsSelected = false;
	private final IDialogCallbackWithPreCommit<List<Customization>, Boolean, D> callback;
	private final List<Customization> lockedCustoms;
	private final String lockMsg;

	public LoadCustomizationsDialog(final Shell parent,
			final List<Customization> availableCustomizations, 
			final List<Customization> selectedCustoms,
			final List<Customization> lockedCustoms,
			final IDialogCallbackWithPreCommit<List<Customization>, Boolean, D> callback,
			final String lockMsg) {
		super(parent);
		this.labelProvider = new ColorLabelProvider(this);
		this.callback = callback;
		this.selectedCustomizations = new BasicEList<Customization>();
		this.availableCustoms = new ArrayList<Customization>(availableCustomizations);
		this.lockedCustoms = lockedCustoms;
		this.lockMsg = lockMsg;
		setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX);
		// initial selection
		for (final Customization initiallySelectedCustomization : selectedCustoms) {
			final URI initiallySelectedCustomizationURI = EcoreUtil
					.getURI(initiallySelectedCustomization);
			final ListIterator<Customization> availableCustomizationsIterator = this.availableCustoms
					.listIterator();
			while (availableCustomizationsIterator.hasNext()) {
				final Customization availableCustomization = availableCustomizationsIterator
						.next();
				final URI availableCustomizationURI = EcoreUtil
						.getURI(availableCustomization);
				if (availableCustomizationURI
						.equals(initiallySelectedCustomizationURI)) {
					availableCustomizationsIterator.remove();
					LoadCustomizationsDialog.this.selectedCustomizations
							.add(initiallySelectedCustomization);
				}

			}
		}
		for (Customization lockedCustom : this.lockedCustoms) {
			if (!this.selectedCustomizations.contains(lockedCustom)) {
				this.selectedCustomizations.add(lockedCustom);
			}
		}
//TODO: Remove before to commit
//		LoadCustomizationsDialog.this.availableCustomizationsTreeViewer
//				.refresh();
//		LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer
//				.refresh();
//TODO(end):  Remove before to commit
	}

	//TODO Remove before to commit
	/** Keep only customizations that apply to the given metamodel */
	/*
	private List<Customization> filterForMetamodel(
			final Collection<Customization> allCustomizations, final Collection<EPackage> ePackages) {
		List<Customization> filteredCustomizations = new ArrayList<Customization>();

		// show only Customizations corresponding to the current EPackages or
		// referenced EPackages
		final Set<EPackage> allReferencedPackages = new HashSet<EPackage>();

		for (EPackage ePackage : ePackages) {
			allReferencedPackages.add(ePackage);
			final Set<EPackage> referencedPackages = ModelUtils.computeReferencedPackages(ePackage);
			allReferencedPackages.addAll(referencedPackages);
		}

		for (Customization metamodelView : Customization) {
			String nsURI = metamodelView.getMetamodelURI();
			EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(nsURI);
			while (ePackage != null) {
				if (allReferencedPackages.contains(ePackage)) {
					filteredCustomizations.add(metamodelView);
					break;
				}
				// allow customizations on Facets
				if (ePackage instanceof FacetSet) {
					FacetSet facetSet = (FacetSet) ePackage;
					ePackage = facetSet.getExtendedPackage();
				} else {
					// allow customizations on sub-packages
					ePackage = ePackage.getESuperPackage();
				}
			}
		}
		return filteredCustomizations;
	}
	*/
	//TODO (end) Remove before to commit

	@Override
	protected void configureShell(final Shell shell) {
		super.configureShell(shell);
		shell.setText(Messages.LoadCustomizationsDialog_title_LoadCustomizations);
	}

	@Override
	protected Control createDialogArea(final Composite parent) {
		final Composite contents = (Composite) super.createDialogArea(parent);

		final GridLayout contentsGridLayout = (GridLayout) contents.getLayout();
		contentsGridLayout.numColumns = LoadCustomizationsDialog.NUM_COLUMNS;

		final GridData contentsGridData = (GridData) contents.getLayoutData();
		contentsGridData.horizontalAlignment = SWT.FILL;
		contentsGridData.verticalAlignment = SWT.FILL;

		createLeftPane(contents);
		createMiddleButtonsPane(contents);
		createRightPane(contents);
		createRightButtonsPane(contents);
		createLoadRequiredFacetsCheckbox(contents);

		this.availableCustomizationsTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
			
			public void doubleClick(final DoubleClickEvent event) {
				loadSelectedCustoms();
			}
		});

		this.selectedCustomizationsTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
			public void doubleClick(final DoubleClickEvent event) {
				unloadSelectedCustoms();
			}
		});

		this.upButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(final SelectionEvent event) {
				upButtonClicked();
			}
		});

		this.downButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(final SelectionEvent event) {
				downButtonClicked();
			}
		});

		this.addButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(final SelectionEvent event) {
				loadSelectedCustoms();
			}
		});

		this.addAllButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(final SelectionEvent event) {
				addAllButtonClicked();
			}
		});

		this.removeButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(final SelectionEvent event) {
				unloadSelectedCustoms();
			}
		});

		this.removeAllButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(final SelectionEvent event) {
				removeAllButtonClicked();
			}
		});

		return contents;
	}

	public final void upButtonClicked() {
		final IStructuredSelection selection = (IStructuredSelection) LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer
				.getSelection();
		int minIndex = 0;
		for (Object selectedObject : selection.toList()) {
			if (selectedObject instanceof Customization) {
				final Customization customization = (Customization) selectedObject;
				final int index = this.selectedCustomizations
						.indexOf(customization);
				this.selectedCustomizations.move(
						Math.max(index - 1, minIndex++), customization);
			}
		}
		LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer.refresh();
	}

	public final void downButtonClicked() {
		final IStructuredSelection selection = (IStructuredSelection) LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer
				.getSelection();
		final ArrayList<Object> selectedObjects = new ArrayList<Object>();
		for (final Object selectedObject : selection.toArray()) {
			selectedObjects.add(selectedObject);
		}

		// prevent the last two elements from swapping
		boolean canMove = !selectedObjects
				.contains(LoadCustomizationsDialog.this.selectedCustomizations
						.get(LoadCustomizationsDialog.this.selectedCustomizations.size() - 1));
		for (int i = LoadCustomizationsDialog.this.selectedCustomizations.size() - 2; i >= 0; i--) {
			final Customization selectedCustomization = LoadCustomizationsDialog.this.selectedCustomizations
					.get(i);
			if (selectedObjects.contains(selectedCustomization)) {
				if (canMove) {
					LoadCustomizationsDialog.this.selectedCustomizations.move(i + 1,
							selectedCustomization);
				}
			} else {
				canMove = true;
			}

		}

		LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer.refresh();
	}

	public final void loadSelectedCustoms() {
		final IStructuredSelection selection = (IStructuredSelection) LoadCustomizationsDialog.this.availableCustomizationsTreeViewer
				.getSelection();
		for (Object object : selection.toList()) {
			if (object instanceof Customization) {
				final Customization custom = (Customization) object;
				if (!this.selectedCustomizations.contains(custom)) {
					this.selectedCustomizations.add(custom);
					this.availableCustoms.remove(custom);
				}
			}
		}
		refresh();
		this.selectedCustomizationsTreeViewer.setSelection(selection);
	}

	public final void addAllButtonClicked() {
		final ListIterator<Customization> listIterator = this.availableCustoms
				.listIterator();
		while (listIterator.hasNext()) {
			final Customization element = listIterator.next();
			this.selectedCustomizations.add(element);
			listIterator.remove();
		}
		refresh();
	}

	public final void unloadSelectedCustoms() {
		final IStructuredSelection selection = (IStructuredSelection) LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer
				.getSelection();
		final List<Customization> toBeRemoved = new ArrayList<Customization>();
		boolean lockedCustomFound = false;
		for (Object object : selection.toList()) {
			if (this.lockedCustoms.contains(object)) {
				lockedCustomFound = true;
			} else if (object instanceof Customization) {
				final Customization element = (Customization) object;
				toBeRemoved.add(element);
			}
		}
		if (lockedCustomFound) {
			final MessageDialog dialog = new MessageDialog(
					null,
					Messages.LoadCustomizationsDialog_LoadCustomizationWarning,
					null,
					Messages.LoadCustomizationsDialog_Can_not_be_unload + this.lockMsg,
					MessageDialog.WARNING, new String[] { Messages.LoadCustomizationsDialog_OK }, 1);
			dialog.open();
		}
		removeFromSelection(toBeRemoved);
		refresh();	
	}

	protected void removeFromSelection(final List<Customization> toBeRemoved) {
		for (final Customization element : toBeRemoved) {
			LoadCustomizationsDialog.this.selectedCustomizations.remove(element);
			LoadCustomizationsDialog.this.availableCustoms.add(element);
		}
		if (LoadCustomizationsDialog.this.selectedCustomizations.size() > 0) {
			LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer
					.setSelection(new StructuredSelection(
							LoadCustomizationsDialog.this.selectedCustomizations.get(0)));
		}
	}

	public final void removeAllButtonClicked() {
		removeFromSelection(this.selectedCustomizations);
		refresh();
	}

	private void createLeftPane(final Composite contents) {
		final Composite choiceComposite = new Composite(contents, SWT.NONE);
		final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
		data.horizontalAlignment = SWT.END;
		choiceComposite.setLayoutData(data);

		final GridLayout layout = new GridLayout();
		data.horizontalAlignment = SWT.FILL;
		layout.marginHeight = 0;
		layout.marginWidth = 0;
		layout.numColumns = 1;
		choiceComposite.setLayout(layout);

		final Label choiceLabel = new Label(choiceComposite, SWT.NONE);
		choiceLabel.setText(Messages.LoadCustomizationsDialog_AvailiableCustom);

		final GridData choiceLabelGridData = new GridData();
		choiceLabelGridData.verticalAlignment = SWT.FILL;
		choiceLabelGridData.horizontalAlignment = SWT.FILL;
		choiceLabel.setLayoutData(choiceLabelGridData);

		final Text patternText = createFilterText(choiceComposite);

		final Tree availableCustomizationsTree = new Tree(choiceComposite, SWT.MULTI | SWT.BORDER);
		final GridData availableCustomizationsGridData = new GridData();
		availableCustomizationsGridData.widthHint = LoadCustomizationsDialog.TREE_WIDTH;
		availableCustomizationsGridData.heightHint = LoadCustomizationsDialog.TREE_HEIGHT;
		availableCustomizationsGridData.horizontalAlignment = SWT.FILL;
		availableCustomizationsGridData.verticalAlignment = SWT.FILL;
		availableCustomizationsGridData.grabExcessHorizontalSpace = true;
		availableCustomizationsGridData.grabExcessVerticalSpace = true;
		availableCustomizationsTree.setLayoutData(availableCustomizationsGridData);

		this.availableCustomizationsTreeViewer = new TreeViewer(availableCustomizationsTree);
		this.availableCustomizationsTreeViewer.setContentProvider(this.contentProvider);
		this.availableCustomizationsTreeViewer.setLabelProvider(this.labelProvider);
		final PatternFilter filter = new PatternFilter();
		this.availableCustomizationsTreeViewer.addFilter(filter);

		this.availableCustomizationsTreeViewer.setInput(this.availableCustoms);

		//TODO Remove before to commit
//		final TreeItem treeItem = new TreeItem(availableCustomizationsTree, SWT.NONE);
//		treeItem.setText(Messages.LoadCustomizationsDialog_Loading);
		//TODO (end) Remove before to commit

		patternText.addModifyListener(new ModifyListener() {
			public void modifyText(final ModifyEvent event) {
				filter.setPattern(patternText.getText());
				LoadCustomizationsDialog.this.availableCustomizationsTreeViewer.refresh();
			}
		});
	}

	private void createMiddleButtonsPane(final Composite contents) {
		final Composite buttonsComposite = new Composite(contents, SWT.NONE);
		final GridData buttonsCompositeGridData = new GridData();
		buttonsCompositeGridData.verticalAlignment = SWT.CENTER;
		buttonsCompositeGridData.horizontalAlignment = SWT.FILL;
		buttonsComposite.setLayoutData(buttonsCompositeGridData);
		buttonsComposite.setLayout(new GridLayout());

		// new Label(buttonsComposite, SWT.NONE);

		this.addButton = new Button(buttonsComposite, SWT.PUSH);
		this.addButton.setText(Messages.LoadCustomizationsDialog_Add);
		this.addButton.setToolTipText(Messages.LoadCustomizationsDialog_Add2);
		final GridData addButtonGridData = new GridData();
		addButtonGridData.verticalAlignment = SWT.FILL;
		addButtonGridData.horizontalAlignment = SWT.FILL;
		this.addButton.setLayoutData(addButtonGridData);

		this.removeButton = new Button(buttonsComposite, SWT.PUSH);
		this.removeButton.setText(Messages.LoadCustomizationsDialog_Remove);
		this.removeButton.setToolTipText(Messages.LoadCustomizationsDialog_Remove2);
		final GridData removeButtonGridData = new GridData();
		removeButtonGridData.verticalAlignment = SWT.FILL;
		removeButtonGridData.horizontalAlignment = SWT.FILL;
		this.removeButton.setLayoutData(removeButtonGridData);

		spacer(buttonsComposite);

		this.addAllButton = new Button(buttonsComposite, SWT.PUSH);
		this.addAllButton.setText(Messages.LoadCustomizationsDialog_AddAll);
		this.addAllButton.setToolTipText(Messages.LoadCustomizationsDialog_AddAll2);

		this.removeAllButton = new Button(buttonsComposite, SWT.PUSH);
		this.removeAllButton.setText(Messages.LoadCustomizationsDialog_RemoveAll);
		this.removeAllButton.setToolTipText(Messages.LoadCustomizationsDialog_RemoveAll2);
	}

	private static void spacer(final Composite parent) {
		Label label = new Label(parent, SWT.NONE);
	}

	private void createRightButtonsPane(final Composite contents) {
		final Composite buttonsComposite = new Composite(contents, SWT.NONE);
		final GridData buttonsCompositeGridData = new GridData();
		buttonsCompositeGridData.verticalAlignment = SWT.FILL;
		buttonsCompositeGridData.horizontalAlignment = SWT.FILL;
		buttonsComposite.setLayoutData(buttonsCompositeGridData);
		buttonsComposite.setLayout(new GridLayout());

		// spacer
		spacer(buttonsComposite);

		this.upButton = new Button(buttonsComposite, SWT.PUSH);
		this.upButton.setText(Messages.LoadCustomizationsDialog_Up);
		final GridData upButtonGridData = new GridData();
		upButtonGridData.verticalAlignment = SWT.FILL;
		upButtonGridData.horizontalAlignment = SWT.FILL;
		this.upButton.setLayoutData(upButtonGridData);

		this.downButton = new Button(buttonsComposite, SWT.PUSH);
		this.downButton.setText(Messages.LoadCustomizationsDialog_Down);
		final GridData downButtonGridData = new GridData();
		downButtonGridData.verticalAlignment = SWT.FILL;
		downButtonGridData.horizontalAlignment = SWT.FILL;
		this.downButton.setLayoutData(downButtonGridData);
	}

	private void createRightPane(final Composite contents) {
		final Composite featureComposite = new Composite(contents, SWT.NONE);
		final GridData featureCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true);
		featureCompositeData.horizontalAlignment = SWT.END;
		featureComposite.setLayoutData(featureCompositeData);

		final GridLayout featureCompositeLayout = new GridLayout();
		featureCompositeData.horizontalAlignment = SWT.FILL;
		featureCompositeLayout.marginHeight = 0;
		featureCompositeLayout.marginWidth = 0;
		featureCompositeLayout.numColumns = 1;
		featureComposite.setLayout(featureCompositeLayout);

		final Label featureLabel = new Label(featureComposite, SWT.NONE);
		featureLabel.setText(Messages.LoadCustomizationsDialog_LoadedCustomizations);
		final GridData featureLabelGridData = new GridData();
		featureLabelGridData.horizontalSpan = 2;
		featureLabelGridData.horizontalAlignment = SWT.FILL;
		featureLabelGridData.verticalAlignment = SWT.FILL;
		featureLabel.setLayoutData(featureLabelGridData);

		final Tree loadedCustomizationsTree = new Tree(featureComposite, SWT.MULTI | SWT.BORDER);
		final GridData loadedCustomizationsGridData = new GridData();
		loadedCustomizationsGridData.widthHint = LoadCustomizationsDialog.TREE_WIDTH;
		loadedCustomizationsGridData.heightHint = LoadCustomizationsDialog.TREE_HEIGHT;
		loadedCustomizationsGridData.verticalAlignment = SWT.FILL;
		loadedCustomizationsGridData.horizontalAlignment = SWT.FILL;
		loadedCustomizationsGridData.grabExcessHorizontalSpace = true;
		loadedCustomizationsGridData.grabExcessVerticalSpace = true;
		loadedCustomizationsTree.setLayoutData(loadedCustomizationsGridData);

		this.selectedCustomizationsTreeViewer = new TreeViewer(loadedCustomizationsTree);
		this.selectedCustomizationsTreeViewer.setContentProvider(this.contentProvider);
		this.selectedCustomizationsTreeViewer.setLabelProvider(this.labelProvider);
		this.selectedCustomizationsTreeViewer.setInput(this.selectedCustomizations);
	}

	private void createLoadRequiredFacetsCheckbox(final Composite contents) {
		spacer(contents);
		spacer(contents);
		this.loadRequiredFacetsCheckbox = new Button(contents, SWT.CHECK);
		this.loadRequiredFacetsCheckbox
				.setText(Messages.LoadCustomizationsDialog_loadReferencedFacetsCheckbox);
		this.loadRequiredFacetsCheckbox.setSelection(true);
		this.loadRequiredFacetsCheckbox
				.setLayoutData(new GridData(SWT.END, SWT.FILL, false, false));

	}

	private static Text createFilterText(final Composite contents) {
		final Text patternText = new Text(contents, SWT.BORDER | SWT.SEARCH);
		patternText.setMessage(Messages.LoadCustomizationsDialog_type_filter_test);
		patternText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		return patternText;
	}

	@Override
	protected void okPressed() {
		pressOk();
	}

	public void commit(final Boolean result) {
		this.callback.committed(this.selectedCustomizations, result);
		super.okPressed();
	}

	public boolean isLoadRequiredFacetsSelected() {
		return this.loadRequiredFacetsSelected;
	}

	// @Override
	// public boolean close() {
	// fContentProvider.dispose();
	// return super.close();
	// }

	public List<Customization> getSelectedCustomizations() {
		return this.selectedCustomizations;
	}

	private void refresh() {
		LoadCustomizationsDialog.this.availableCustomizationsTreeViewer.refresh();
		LoadCustomizationsDialog.this.selectedCustomizationsTreeViewer.refresh();
	}

	public void asyncOpen() {
		Display display;
		if (this.getShell() == null) {
			display = Display.getDefault();
		} else {
			display = this.getShell().getDisplay();
		}
		display.asyncExec(new Runnable() {
			public void run() {
				LoadCustomizationsDialog.this.open();
			}
		});
	}

	public D pressOk() {
		this.loadRequiredFacetsSelected = this.loadRequiredFacetsCheckbox
				.getSelection();
		final D preCommitDialog = this.callback
				.openPrecommitDialog(this.selectedCustomizations,
						new IDialogCallback<Boolean>() {
							public void committed(final Boolean result) {
								if (result.booleanValue()) {
									LoadCustomizationsDialog.this
											.commit(result);
								}
							}
						});
		if (preCommitDialog == null) {
			this.callback.committed(this.selectedCustomizations, Boolean.TRUE);
			super.okPressed();
		}
		return preCommitDialog;
	}

	public void selectAvailableCustom(final Customization customization) {
		final ISelection selection = new StructuredSelection(customization);
		this.availableCustomizationsTreeViewer.setSelection(selection);
	}

	public void selectSelectedCustom(final Customization customization) {
		final ISelection selection = new StructuredSelection(customization);
		this.selectedCustomizationsTreeViewer.setSelection(selection);
		
	}

	public List<Customization> getLockedCustoms() {
		return this.lockedCustoms;
	}

	public void addCustomization(final Customization customization)
			throws IllegalParameterException {
		// TODO Auto-generated method stub

	}

	public void addCustomizations(final List<Customization> customizations)
			throws IllegalParameterException {
		// TODO Auto-generated method stub

	}

	public void removeCustomization(final Customization customization)
			throws IllegalParameterException {
		// TODO Auto-generated method stub

	}

	public void removeCustomizations(final List<Customization> customizations)
			throws IllegalParameterException {
		// TODO Auto-generated method stub

	}

	public void cancel() {
		// TODO Auto-generated method stub

	}

	public void validate() {
		// TODO Auto-generated method stub

	}

	public List<Customization> getAvailableCustomizations() {
		// TODO Auto-generated method stub
		return null;
	}

	public void pushUp(final Customization customization)
			throws IllegalParameterException {
		// TODO Auto-generated method stub

	}

	public void pushDown(final Customization customization)
			throws IllegalParameterException {
		// TODO Auto-generated method stub

	}
}

Back to the top