Project

General

Profile

Download (8.62 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
/*
12
 * Created on Feb 9, 2004
13
 *  
14
 */
15
package org.eclipse.ui.internal.navigator.filters;
16

    
17
import java.util.ArrayList;
18
import java.util.Iterator;
19
import java.util.List;
20
import java.util.Set;
21

    
22
import org.eclipse.jface.dialogs.TrayDialog;
23
import org.eclipse.jface.resource.ColorRegistry;
24
import org.eclipse.jface.resource.JFaceResources;
25
import org.eclipse.jface.viewers.ISelectionChangedListener;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.custom.CTabFolder;
28
import org.eclipse.swt.custom.CTabItem;
29
import org.eclipse.swt.events.SelectionEvent;
30
import org.eclipse.swt.events.SelectionListener;
31
import org.eclipse.swt.graphics.Color;
32
import org.eclipse.swt.layout.GridData;
33
import org.eclipse.swt.layout.GridLayout;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.swt.widgets.Label;
37
import org.eclipse.swt.widgets.TableItem;
38
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.internal.navigator.CommonNavigatorMessages;
40
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
41
import org.eclipse.ui.navigator.CommonViewer;
42
import org.eclipse.ui.navigator.ICommonFilterDescriptor;
43
import org.eclipse.ui.navigator.INavigatorContentDescriptor;
44
import org.eclipse.ui.navigator.INavigatorContentService;
45
import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
46

    
47
/**
48
 * 
49
 * @since 3.2
50
 * 
51
 */
52
public class CommonFilterSelectionDialog extends TrayDialog {
53
   
54
	private static final String FILTER_ICON = "icons/full/elcl16/filter_ps.gif"; //$NON-NLS-1$
55
	private static final String CONTENT_ICON = "icons/full/elcl16/content.gif"; //$NON-NLS-1$
56

    
57
	private static final int TAB_WIDTH_IN_DLUS = 300;
58

    
59
	private static final int TAB_HEIGHT_IN_DLUS = 150;
60

    
61
	private final CommonViewer commonViewer;
62

    
63
	private final INavigatorContentService contentService;
64

    
65
	private CTabFolder customizationsTabFolder;
66

    
67
	private CommonFiltersTab commonFiltersTab;
68

    
69
	private ContentExtensionsTab contentExtensionsTab;
70

    
71
	private Label descriptionText;
72

    
73
	private ISelectionChangedListener updateDescriptionSelectionListener; 
74

    
75
	private String helpContext;
76
	
77
	/**
78
	 * Public only for tests.
79
	 * 
80
	 * @param aCommonViewer
81
	 */
82
	public CommonFilterSelectionDialog(CommonViewer aCommonViewer) {
83
		super(aCommonViewer.getControl().getShell());
84
		setShellStyle(SWT.RESIZE | getShellStyle());
85

    
86
		commonViewer = aCommonViewer;
87
		contentService = commonViewer.getNavigatorContentService();
88

    
89
		INavigatorViewerDescriptor viewerDescriptor = contentService.getViewerDescriptor();
90
		helpContext = viewerDescriptor
91
				.getStringConfigProperty(INavigatorViewerDescriptor.PROP_CUSTOMIZE_VIEW_DIALOG_HELP_CONTEXT);
92

    
93
		if (helpContext != null) {
94
			PlatformUI.getWorkbench().getHelpSystem().setHelp(
95
					aCommonViewer.getControl().getShell(), helpContext);
96
		}
97
	}
98

    
99
	public boolean isHelpAvailable() {
100
		return helpContext != null;
101
	}
102

    
103
	/*
104
	 * (non-Javadoc)
105
	 * 
106
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
107
	 */
108
	protected Control createDialogArea(Composite parent) {
109
		 
110
		getShell()
111
				.setText(
112
						CommonNavigatorMessages.CommonFilterSelectionDialog_Available_customization_);
113
		 
114
		
115
		Composite superComposite = (Composite) super.createDialogArea(parent);
116
		 
117
		createCustomizationsTabFolder(superComposite); 
118
		
119
		commonFiltersTab = new CommonFiltersTab(customizationsTabFolder,
120
				contentService);
121
		createTabItem(
122
				customizationsTabFolder,
123
				CommonNavigatorMessages.CommonFilterSelectionDialog_Available_Filters,
124
				commonFiltersTab, FILTER_ICON);
125
		
126

    
127
		boolean hideExtensionsTab = contentService.getViewerDescriptor()
128
				.getBooleanConfigProperty(
129
						INavigatorViewerDescriptor.PROP_HIDE_AVAILABLE_EXT_TAB);
130

    
131
		if (!hideExtensionsTab) { 
132
			contentExtensionsTab = new ContentExtensionsTab(
133
					customizationsTabFolder, contentService);
134

    
135
			createTabItem(
136
					customizationsTabFolder,
137
					CommonNavigatorMessages.CommonFilterSelectionDialog_Available_Content,
138
					contentExtensionsTab, CONTENT_ICON);
139
			
140
		}
141

    
142
		createDescriptionText(superComposite);
143

    
144
		if (commonFiltersTab != null) {
145
			commonFiltersTab.addSelectionChangedListener(getSelectionListener());
146
		}
147

    
148
		if (contentExtensionsTab != null) {
149
			contentExtensionsTab
150
					.addSelectionChangedListener(getSelectionListener());
151
		}
152
	
153
		commonFiltersTab.setInitialFocus();
154
		
155
		return customizationsTabFolder;
156
	}
157

    
158
	private void createCustomizationsTabFolder(Composite superComposite) {
159
		customizationsTabFolder = new CTabFolder (superComposite, SWT.RESIZE | SWT.BORDER);
160
 
161
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
162
		gd.widthHint = convertHorizontalDLUsToPixels(TAB_WIDTH_IN_DLUS);
163
		gd.heightHint = convertVerticalDLUsToPixels(TAB_HEIGHT_IN_DLUS);
164
		
165
		customizationsTabFolder.setLayout(new GridLayout());
166
		customizationsTabFolder.setLayoutData(gd);
167

    
168
		customizationsTabFolder.setFont(superComposite.getFont()); 
169

    
170
		customizationsTabFolder.addSelectionListener(new SelectionListener() {
171

    
172
			public void widgetSelected(SelectionEvent e) {
173
				if (descriptionText != null) {
174
					descriptionText.setText(""); //$NON-NLS-1$
175
				}
176
			}
177

    
178
			public void widgetDefaultSelected(SelectionEvent e) {
179

    
180
			}
181

    
182
		});
183
	  
184
		customize();
185

    
186
	}
187

    
188
	private void customize() {
189
		ColorRegistry reg = JFaceResources.getColorRegistry();
190
		Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$
191
		  c2 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"); //$NON-NLS-1$
192
		customizationsTabFolder.setSelectionBackground(new Color[] {c1, c2},	new int[] {100}, true);
193
		customizationsTabFolder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$
194
//		RAP [bmichalik]
195
//		customizationsTabFolder.setSimple(true);
196
	}
197

    
198
	private CTabItem createTabItem(CTabFolder aTabFolder, String label,
199
			Composite composite, String imageKey) {
200
		CTabItem extensionsTabItem = new CTabItem(aTabFolder, SWT.BORDER);
201
		extensionsTabItem.setText(label);
202
 		extensionsTabItem.setControl(composite); 
203
 		extensionsTabItem.setImage(NavigatorPlugin.getDefault().getImage(imageKey));
204
 		return extensionsTabItem;
205
	}
206

    
207
	private void createDescriptionText(Composite composite) {
208

    
209
		descriptionText = new Label(composite, SWT.WRAP);
210
		descriptionText.setFont(composite.getFont());
211
		descriptionText.setBackground(composite.getBackground());
212
		GridData descriptionTextGridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
213
		descriptionTextGridData.heightHint = convertHeightInCharsToPixels(3);
214
		descriptionText.setLayoutData(descriptionTextGridData);
215
	}
216

    
217
	private ISelectionChangedListener getSelectionListener() {
218
		if (updateDescriptionSelectionListener == null) {
219
			updateDescriptionSelectionListener = new FilterDialogSelectionListener(
220
					descriptionText);
221
		}
222
		return updateDescriptionSelectionListener;
223
	}
224

    
225
	/*
226
	 * (non-Javadoc)
227
	 * 
228
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
229
	 */
230
	protected void okPressed() {
231

    
232
		if (contentExtensionsTab != null) {
233
			List checkedExtensions = new ArrayList();
234
			TableItem[] tableItems = contentExtensionsTab.getTable().getItems();
235
			INavigatorContentDescriptor descriptor;
236
			for (int i = 0; i < tableItems.length; i++) {
237
				descriptor = (INavigatorContentDescriptor) tableItems[i]
238
						.getData();
239

    
240
				if (tableItems[i].getChecked()) {
241
					checkedExtensions.add(descriptor.getId());
242
				}
243
			}
244
			String[] contentExtensionIdsToActivate = (String[]) checkedExtensions
245
					.toArray(new String[checkedExtensions.size()]);
246
			UpdateActiveExtensionsOperation updateExtensions = new UpdateActiveExtensionsOperation(
247
					commonViewer, contentExtensionIdsToActivate);
248
			updateExtensions.execute(null, null);
249
		}
250

    
251
		if (commonFiltersTab != null) {
252
			Set checkedFilters = commonFiltersTab.getCheckedItems();
253
			
254
			String[] filterIdsToActivate = new String[checkedFilters.size()];
255
			int indx = 0;
256
			for (Iterator iterator = checkedFilters.iterator(); iterator
257
					.hasNext();) {
258
				ICommonFilterDescriptor descriptor = (ICommonFilterDescriptor) iterator
259
						.next();
260

    
261
				filterIdsToActivate[indx++] = descriptor.getId();
262

    
263
			} 
264
			UpdateActiveFiltersOperation updateFilters = new UpdateActiveFiltersOperation(
265
					commonViewer, filterIdsToActivate);
266
			updateFilters.execute(null, null);
267
		}
268

    
269
		super.okPressed();
270
	}
271
}
(5-5/17)