1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Copied and adapted from NewFolderDialog
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.dialogs
;
16 import java
.util
.Arrays
;
18 import org
.eclipse
.core
.resources
.IResource
;
19 import org
.eclipse
.jface
.dialogs
.Dialog
;
20 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
21 import org
.eclipse
.jface
.viewers
.CheckboxTreeViewer
;
22 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
23 import org
.eclipse
.jface
.viewers
.LabelProvider
;
24 import org
.eclipse
.jface
.viewers
.Viewer
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.graphics
.Point
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Control
;
31 import org
.eclipse
.swt
.widgets
.Group
;
32 import org
.eclipse
.swt
.widgets
.Shell
;
33 import org
.eclipse
.swt
.widgets
.Tree
;
34 import org
.eclipse
.ui
.ISharedImages
;
35 import org
.eclipse
.ui
.PlatformUI
;
38 * SelectSupplementaryResourcesDialog
40 public class SelectSupplementaryResourcesDialog
extends Dialog
{
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
45 private CheckboxTreeViewer fTreeViewer
;
46 private final IResource
[] fAvailableResources
;
47 private IResource
[] fReturndResources
;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
57 * Parent shell of this dialog
61 public SelectSupplementaryResourcesDialog(Shell shell
, IResource
[] resources
) {
63 fAvailableResources
= Arrays
.copyOf(resources
, resources
.length
);
64 setShellStyle(SWT
.RESIZE
);
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 * @return A copy of the resources
74 public IResource
[] getResources() {
75 return Arrays
.copyOf(fReturndResources
, fReturndResources
.length
);
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
83 protected void configureShell(Shell newShell
) {
84 super.configureShell(newShell
);
85 newShell
.setText(Messages
.SelectSpplementaryResources_DialogTitle
);
86 newShell
.setImage(PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_ETOOL_DELETE
));
90 protected Control
createDialogArea(Composite parent
) {
91 Composite composite
= (Composite
) super.createDialogArea(parent
);
92 composite
.setLayout(new GridLayout());
93 composite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
95 Group contextGroup
= new Group(composite
, SWT
.SHADOW_NONE
);
96 contextGroup
.setText(Messages
.SelectSpplementaryResources_ResourcesGroupTitle
);
97 contextGroup
.setLayout(new GridLayout());
98 contextGroup
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
100 fTreeViewer
= new CheckboxTreeViewer(contextGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
101 GridData data
= new GridData(GridData
.FILL_BOTH
);
102 Tree tree
= fTreeViewer
.getTree();
103 tree
.setLayoutData(data
);
104 fTreeViewer
.setContentProvider(new ITreeContentProvider() {
107 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
111 public void dispose() {
115 public boolean hasChildren(Object element
) {
116 if (element
instanceof IResource
[]) {
123 public Object
getParent(Object element
) {
128 public Object
[] getElements(Object inputElement
) {
129 return getChildren(inputElement
);
133 public Object
[] getChildren(Object parentElement
) {
134 if (parentElement
instanceof IResource
[]) {
135 return (Object
[]) parentElement
;
141 // fTreeViewer.setLabelProvider(new WorkbenchLabelProvider());
143 fTreeViewer
.setLabelProvider(new LabelProvider() {
145 public String
getText(Object element
) {
146 if (element
instanceof IResource
) {
147 IResource resource
= (IResource
) element
;
148 // show also trace name
149 return resource
.getParent().getName() + File
.separator
+ resource
.getName();
151 return super.getText(element
);
154 fTreeViewer
.setInput(fAvailableResources
);
156 getShell().setMinimumSize(new Point(300, 150));
162 protected void createButtonsForButtonBar(Composite parent
) {
163 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
164 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
168 protected void okPressed() {
169 Object
[] checked
= fTreeViewer
.getCheckedElements();
171 fReturndResources
= new IResource
[checked
.length
];
172 for (int i
= 0; i
< checked
.length
; i
++) {
173 fReturndResources
[i
] = (IResource
) checked
[i
];