tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / dialogs / SelectSupplementaryResourcesDialog.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Copied and adapted from NewFolderDialog
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui.project.dialogs;
14
15 import java.io.File;
16 import java.util.Arrays;
17
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;
36
37 /**
38 * SelectSupplementaryResourcesDialog
39 */
40 public class SelectSupplementaryResourcesDialog extends Dialog {
41
42 // ------------------------------------------------------------------------
43 // Members
44 // ------------------------------------------------------------------------
45 private CheckboxTreeViewer fTreeViewer;
46 private final IResource[] fAvailableResources;
47 private IResource[] fReturndResources;
48
49 // ------------------------------------------------------------------------
50 // Constructor
51 // ------------------------------------------------------------------------
52
53 /**
54 * Constructor.
55 *
56 * @param shell
57 * Parent shell of this dialog
58 * @param resources
59 * Available resources
60 */
61 public SelectSupplementaryResourcesDialog(Shell shell, IResource[] resources) {
62 super(shell);
63 fAvailableResources = Arrays.copyOf(resources, resources.length);
64 setShellStyle(SWT.RESIZE);
65 }
66
67 // ------------------------------------------------------------------------
68 // Getters/Setters
69 // ------------------------------------------------------------------------
70
71 /**
72 * @return A copy of the resources
73 */
74 public IResource[] getResources() {
75 return Arrays.copyOf(fReturndResources, fReturndResources.length);
76 }
77
78 // ------------------------------------------------------------------------
79 // Dialog
80 // ------------------------------------------------------------------------
81
82 /*
83 * (non-Javadoc)
84 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
85 */
86 @Override
87 protected void configureShell(Shell newShell) {
88 super.configureShell(newShell);
89 newShell.setText(Messages.SelectSpplementaryResources_DialogTitle);
90 newShell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE));
91 }
92
93 @Override
94 protected Control createDialogArea(Composite parent) {
95 Composite composite = (Composite) super.createDialogArea(parent);
96 composite.setLayout(new GridLayout());
97 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
98
99 Group contextGroup = new Group(composite, SWT.SHADOW_NONE);
100 contextGroup.setText(Messages.SelectSpplementaryResources_ResourcesGroupTitle);
101 contextGroup.setLayout(new GridLayout());
102 contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
103
104 fTreeViewer = new CheckboxTreeViewer(contextGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
105 GridData data = new GridData(GridData.FILL_BOTH);
106 Tree tree = fTreeViewer.getTree();
107 tree.setLayoutData(data);
108 fTreeViewer.setContentProvider(new ITreeContentProvider() {
109
110 @Override
111 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
112 }
113
114 @Override
115 public void dispose() {
116 }
117
118 @Override
119 public boolean hasChildren(Object element) {
120 if (element instanceof IResource[]) {
121 return true;
122 }
123 return false;
124 }
125
126 @Override
127 public Object getParent(Object element) {
128 return null;
129 }
130
131 @Override
132 public Object[] getElements(Object inputElement) {
133 return getChildren(inputElement);
134 }
135
136 @Override
137 public Object[] getChildren(Object parentElement) {
138 if (parentElement instanceof IResource[]) {
139 return (Object[]) parentElement;
140 }
141 return null;
142 }
143 });
144
145 // fTreeViewer.setLabelProvider(new WorkbenchLabelProvider());
146
147 fTreeViewer.setLabelProvider(new LabelProvider() {
148 @Override
149 public String getText(Object element) {
150 if (element instanceof IResource) {
151 IResource resource = (IResource) element;
152 // show also trace name
153 return resource.getParent().getName() + File.separator + resource.getName();
154 }
155 return super.getText(element);
156 }
157 });
158 fTreeViewer.setInput(fAvailableResources);
159
160 getShell().setMinimumSize(new Point(300, 150));
161
162 return composite;
163 }
164
165 /*
166 * (non-Javadoc)
167 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
168 */
169 @Override
170 protected void createButtonsForButtonBar(Composite parent) {
171 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
172 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
173 }
174
175 @Override
176 protected void okPressed() {
177 Object[] checked = fTreeViewer.getCheckedElements();
178
179 fReturndResources = new IResource[checked.length];
180 for (int i = 0; i < checked.length; i++) {
181 fReturndResources[i] = (IResource) checked[i];
182 }
183 super.okPressed();
184 }
185
186 }
This page took 0.037077 seconds and 5 git commands to generate.