~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

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