2
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.carbide.cpp.internal.codescanner.ui;
|
|
19 |
|
|
20 |
import org.eclipse.core.resources.IProject;
|
|
21 |
import org.eclipse.core.runtime.CoreException;
|
|
22 |
import org.eclipse.core.runtime.IStatus;
|
|
23 |
import org.eclipse.core.runtime.Status;
|
|
24 |
import org.eclipse.jface.viewers.ArrayContentProvider;
|
|
25 |
import org.eclipse.jface.viewers.DoubleClickEvent;
|
|
26 |
import org.eclipse.jface.viewers.IDoubleClickListener;
|
|
27 |
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
|
28 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
29 |
import org.eclipse.jface.viewers.ITableLabelProvider;
|
|
30 |
import org.eclipse.jface.viewers.LabelProvider;
|
|
31 |
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
|
32 |
import org.eclipse.jface.viewers.TableViewer;
|
|
33 |
import org.eclipse.swt.SWT;
|
|
34 |
import org.eclipse.swt.graphics.Image;
|
|
35 |
import org.eclipse.swt.layout.GridData;
|
|
36 |
import org.eclipse.swt.widgets.Composite;
|
|
37 |
import org.eclipse.swt.widgets.Control;
|
|
38 |
import org.eclipse.swt.widgets.Shell;
|
|
39 |
import org.eclipse.swt.widgets.TableItem;
|
|
40 |
import org.eclipse.ui.dialogs.SelectionStatusDialog;
|
|
41 |
|
|
42 |
import com.nokia.carbide.cpp.internal.codescanner.CSPlugin;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* A class to handle selection of a project.
|
|
46 |
*/
|
|
47 |
public class CSProjectSelectionDialog extends SelectionStatusDialog {
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Inner class to handle labels of the project selection table.
|
|
51 |
*/
|
|
52 |
private class CSProjectLabelProvider extends LabelProvider implements
|
|
53 |
ITableLabelProvider {
|
|
54 |
|
|
55 |
public String getColumnText(Object element, int index) {
|
|
56 |
IProject project = (IProject) element;
|
|
57 |
String projectName = "";
|
|
58 |
try {
|
|
59 |
projectName = project.getDescription().getName();
|
|
60 |
}
|
|
61 |
catch (CoreException e) {
|
|
62 |
//ignore
|
|
63 |
}
|
|
64 |
return projectName;
|
|
65 |
}
|
|
66 |
|
|
67 |
public Image getColumnImage(Object element, int index) {
|
|
68 |
return null;
|
|
69 |
}
|
|
70 |
|
|
71 |
}
|
|
72 |
|
|
73 |
// private members for various controls of this preference page
|
|
74 |
private IProject[] projects;
|
|
75 |
private TableViewer tableViewer;
|
|
76 |
|
|
77 |
/**
|
|
78 |
* Create an instance of this dialog.
|
|
79 |
* @param parentShell
|
|
80 |
* @param projectList - list of projects to be displayed in this dialog
|
|
81 |
*/
|
|
82 |
CSProjectSelectionDialog(Shell parentShell, IProject[] projectList) {
|
|
83 |
super(parentShell);
|
|
84 |
setTitle("Project Specific Settings");
|
|
85 |
setMessage("Select the project to configure :");
|
|
86 |
projects = projectList;
|
|
87 |
|
|
88 |
int shellStyle = getShellStyle();
|
|
89 |
setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE);
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Create contents of this dialog.
|
|
94 |
* @param parent - the parent composite
|
|
95 |
*/
|
|
96 |
protected Control createDialogArea(Composite parent) {
|
|
97 |
Composite container = (Composite)super.createDialogArea(parent);
|
|
98 |
createMessageArea(container);
|
|
99 |
|
|
100 |
tableViewer = new TableViewer(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
|
|
101 |
GridData data= new GridData(SWT.FILL, SWT.FILL, true, true);
|
|
102 |
data.heightHint= 200;
|
|
103 |
data.widthHint= 200;
|
|
104 |
tableViewer.getTable().setLayoutData(data);
|
|
105 |
tableViewer.setLabelProvider(new CSProjectLabelProvider());
|
|
106 |
tableViewer.setContentProvider(new ArrayContentProvider());
|
|
107 |
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
|
108 |
public void selectionChanged(SelectionChangedEvent event) {
|
|
109 |
doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray());
|
|
110 |
}
|
|
111 |
});
|
|
112 |
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
|
|
113 |
public void doubleClick(DoubleClickEvent event) {
|
|
114 |
okPressed();
|
|
115 |
}
|
|
116 |
});
|
|
117 |
|
|
118 |
initializeTable();
|
|
119 |
doSelectionChanged(null);
|
|
120 |
return container;
|
|
121 |
}
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Compute the result and return it.
|
|
125 |
*/
|
|
126 |
protected void computeResult() {
|
|
127 |
}
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Handle selection within this dialog.
|
|
131 |
* @param objects - objects selected
|
|
132 |
*/
|
|
133 |
private void doSelectionChanged(Object[] objects) {
|
|
134 |
if (objects == null || objects.length != 1) {
|
|
135 |
updateStatus(new Status(IStatus.ERROR, CSPlugin.PLUGIN_ID, ""));
|
|
136 |
setSelectionResult(null);
|
|
137 |
} else {
|
|
138 |
updateStatus(new Status(IStatus.OK, CSPlugin.PLUGIN_ID, ""));
|
|
139 |
setSelectionResult(objects);
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
/**
|
|
144 |
* Initialize the project selection table.
|
|
145 |
*/
|
|
146 |
private void initializeTable() {
|
|
147 |
for (int i = 0; i < projects.length; i++) {
|
|
148 |
TableItem tableItem = new TableItem(tableViewer.getTable(), SWT.LEFT, i);
|
|
149 |
tableItem.setData(projects[i]);
|
|
150 |
tableItem.setText(projects[i].getName());
|
|
151 |
}
|
|
152 |
}
|
|
153 |
}
|