View | Details | Raw Unified | Return to bug 109045 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (+6 lines)
Lines 104-106 Link Here
104
##
104
##
105
Java_Element_hyperlink=Java Element
105
Java_Element_hyperlink=Java Element
106
Taglib_hyperlink=Tag Library Descriptor
106
Taglib_hyperlink=Tag Library Descriptor
107
108
HideImportDeclaration.label=Import Directive
109
HideImportDeclaration.description=Hides Import Directives
110
111
HideFontStyle.label=Font Style
112
HideFontStyle.description=Hides Font Style Tags
(-)plugin.xml (+20 lines)
Lines 1071-1074 Link Here
1071
			</contentTypeIdentifier>
1071
			</contentTypeIdentifier>
1072
		</inserter>
1072
		</inserter>
1073
	</extension>
1073
	</extension>
1074
 <extension
1075
       point="org.eclipse.wst.sse.ui.sseElementFilter">
1076
       <filter
1077
            targetId="org.eclipse.jst.jsp.ui.OutlinePage"
1078
            name="%HideImportDeclaration.label"
1079
            enabled="false"
1080
            description="%HideImportDeclaration.description"
1081
            class="org.eclipse.jdt.internal.ui.filters.ImportDeclarationFilter"
1082
            id="org.eclipse.jst.jsp.ui.filters.ImportDeclarationFilter">
1083
       </filter>
1084
       <filter
1085
            targetId="org.eclipse.jst.jsp.ui.OutlinePage"
1086
           name="%HideFontStyle.label"
1087
            enabled="false"
1088
            description="%HideFontStyle.description"
1089
            class="org.eclipse.wst.html.ui.views.contentoutline.HTMLFontStyleFilter"
1090
            id="org.eclipse.jst.jsp.ui.views.contentoutline.HTMLFontStyleFilter">
1091
       </filter>
1092
 </extension>
1093
	
1074
</plugin>
1094
</plugin>
(-)src/org/eclipse/jst/jsp/ui/views/contentoutline/JSPContentOutlineConfiguration.java (-1 / +2 lines)
Lines 31-43 Link Here
31
	// be used
31
	// be used
32
	// private StructuredContentOutlineConfiguration fEmbeddedConfiguration =
32
	// private StructuredContentOutlineConfiguration fEmbeddedConfiguration =
33
	// null;
33
	// null;
34
34
	private final String OUTLINE_FILTER_PREF = "org.eclipse.jst.jsp.ui.OutlinePage"; //$NON-NLS-1$
35
	/**
35
	/**
36
	 * Create new instance of JSPContentOutlineConfiguration
36
	 * Create new instance of JSPContentOutlineConfiguration
37
	 */
37
	 */
38
	public JSPContentOutlineConfiguration() {
38
	public JSPContentOutlineConfiguration() {
39
		// Must have empty constructor to createExecutableExtension
39
		// Must have empty constructor to createExecutableExtension
40
		super();
40
		super();
41
		super.setOutlineFilterTarget(OUTLINE_FILTER_PREF);
41
	}
42
	}
42
43
43
	/*
44
	/*
(-)plugin.properties (+2 lines)
Lines 76-78 Link Here
76
hyperlink.target.script.name=HTML Client Script
76
hyperlink.target.script.name=HTML Client Script
77
hyperlink.target.eventhandler.name=HTML Event Handlers
77
hyperlink.target.eventhandler.name=HTML Event Handlers
78
78
79
HideFontStyle.label=Font Style
80
HideFontStyle.description=Hides Font Style Tags
(-)plugin.xml (+12 lines)
Lines 636-640 Link Here
636
			</contentTypeIdentifier>
636
			</contentTypeIdentifier>
637
		</inserter>
637
		</inserter>
638
	</extension>
638
	</extension>
639
 <extension
640
       point="org.eclipse.wst.sse.ui.sseElementFilter">
641
       <filter
642
            targetId="org.eclipse.wst.html.ui.OutlinePage"
643
            name="%HideFontStyle.label"
644
            enabled="false"
645
            description="%HideFontStyle.description"
646
            class="org.eclipse.wst.html.ui.views.contentoutline.HTMLFontStyleFilter"
647
            id="org.eclipse.wst.html.ui.views.contentoutline.HTMLFontStyleFilter">
648
      </filter>
649
 </extension>
650
	
639
	
651
	
640
</plugin>
652
</plugin>
(-)src/org/eclipse/wst/html/ui/views/contentoutline/HTMLContentOutlineConfiguration.java (-1 / +3 lines)
Lines 25-37 Link Here
25
 * @since 1.0
25
 * @since 1.0
26
 */
26
 */
27
public class HTMLContentOutlineConfiguration extends XMLContentOutlineConfiguration {
27
public class HTMLContentOutlineConfiguration extends XMLContentOutlineConfiguration {
28
28
	private final String OUTLINE_FILTER_PREF = "org.eclipse.wst.html.ui.OutlinePage"; //$NON-NLS-1$
29
	/**
29
	/**
30
	 * Create new instance of HTMLContentOutlineConfiguration
30
	 * Create new instance of HTMLContentOutlineConfiguration
31
	 */
31
	 */
32
	public HTMLContentOutlineConfiguration() {
32
	public HTMLContentOutlineConfiguration() {
33
		// Must have empty constructor to createExecutableExtension
33
		// Must have empty constructor to createExecutableExtension
34
		super();
34
		super();
35
		super.setOutlineFilterTarget(OUTLINE_FILTER_PREF);
36
		
35
	}
37
	}
36
38
37
	protected XMLNodeActionManager createNodeActionManager(TreeViewer treeViewer) {
39
	protected XMLNodeActionManager createNodeActionManager(TreeViewer treeViewer) {
(-)src/org/eclipse/wst/html/ui/views/contentoutline/HTMLFontStyleFilter.java (+36 lines)
Added Link Here
1
package org.eclipse.wst.html.ui.views.contentoutline;
2
3
import java.util.ArrayList;
4
5
import org.eclipse.jface.viewers.Viewer;
6
import org.eclipse.jface.viewers.ViewerFilter;
7
import org.eclipse.wst.html.core.internal.document.ElementStyleImpl;
8
import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace;
9
10
public class HTMLFontStyleFilter extends ViewerFilter {
11
	final static ArrayList fontStyles = new ArrayList(9);
12
	static {
13
		
14
		fontStyles.add(HTML40Namespace.ElementName.TT.toLowerCase());
15
		fontStyles.add(HTML40Namespace.ElementName.I.toLowerCase());
16
		fontStyles.add(HTML40Namespace.ElementName.B.toLowerCase());
17
		fontStyles.add(HTML40Namespace.ElementName.P.toLowerCase());
18
		fontStyles.add(HTML40Namespace.ElementName.S.toLowerCase());
19
		fontStyles.add(HTML40Namespace.ElementName.STRIKE.toLowerCase());
20
		fontStyles.add(HTML40Namespace.ElementName.BIG.toLowerCase());
21
		fontStyles.add(HTML40Namespace.ElementName.SMALL.toLowerCase());
22
		fontStyles.add(HTML40Namespace.ElementName.U.toLowerCase());
23
	}
24
25
	public boolean select(Viewer viewer, Object parentElement, Object element) {
26
		if (element instanceof ElementStyleImpl){
27
			ElementStyleImpl elemImpl = (ElementStyleImpl)element;
28
			String nodeName = elemImpl.getNodeName().toLowerCase();
29
			if (fontStyles.contains(nodeName)){
30
				return false;
31
			}
32
		}
33
		return true;
34
	}
35
36
}
(-)plugin.properties (+8 lines)
Lines 105-107 Link Here
105
Colors.content_assist_proposals_foreground=Content Assist Proposals Foreground
105
Colors.content_assist_proposals_foreground=Content Assist Proposals Foreground
106
Colors.content_assist_parameters_background=Content Assist Parameters Background
106
Colors.content_assist_parameters_background=Content Assist Parameters Background
107
Colors.content_assist_parameters_foreground=Content Assist Parameters Foreground
107
Colors.content_assist_parameters_foreground=Content Assist Parameters Foreground
108
109
#Filter Support
110
111
HideImportDeclaration.label= Import declarations
112
HideImportDeclaration.description= Hides all import declarations
113
114
115
elementFiltersName=SSE Element Filters
(-)plugin.xml (+3 lines)
Lines 519-524 Link Here
519
		id="quickFixProcessor" 
519
		id="quickFixProcessor" 
520
		name="%quickFixProcessor" 
520
		name="%quickFixProcessor" 
521
		schema="schema/quickFixProcessor.exsd"/>
521
		schema="schema/quickFixProcessor.exsd"/>
522
 <extension-point id="sseElementFilter" name="%elementFiltersName" schema="schema/sseElementFilter.exsd"/>
522
 
523
 
523
	<extension point="org.eclipse.ui.menus">
524
	<extension point="org.eclipse.ui.menus">
524
		<menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=edit">
525
		<menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=edit">
Lines 766-770 Link Here
766
		</colorDefinition>
767
		</colorDefinition>
767
	</extension>
768
	</extension>
768
	
769
	
770
771
	
769
</plugin>
772
</plugin>
770
773
(-)schema/sseElementFilter.exsd (+155 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.wst.sse.ui" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.wst.sse.ui" id="sseElementFilter" name="%elementFiltersName"/>
7
      </appInfo>
8
      <documentation>
9
         [Enter description of this extension point.]
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
   	  <complexType>
15
         <sequence>
16
            <element ref="filter" minOccurs="1" maxOccurs="unbounded"/>
17
         </sequence>
18
         <attribute name="point" type="string" use="required">
19
         	<annotation>
20
         	   <documentation>
21
                  a fully qualified identifier of the target extension point
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  an optional identifier of the extension instance
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  an optional name of the extension instance
36
               </documentation>
37
               <appInfo>
38
                  <meta.attribute translatable="true"/>
39
               </appInfo>
40
            </annotation>
41
         </attribute>
42
      </complexType>
43
   </element>
44
45
   <element name="filter">
46
      <annotation>
47
         <appInfo>
48
            <meta.element labelAttribute="name"/>
49
         </appInfo>
50
      </annotation>
51
      <complexType>
52
         <attribute name="id" type="string">
53
            <annotation>
54
               <documentation>
55
                  a unique id that will be used to identify this filter
56
               </documentation>
57
            </annotation>
58
         </attribute>
59
         <attribute name="name" type="string">
60
            <annotation>
61
               <documentation>
62
                  a unique name that allows to identify this filter in the UI. This attribute should be a translated string. Though this attribute is not required for pattern filters (i.e. those using the &lt;samp&gt;pattern&lt;/samp&gt; attribute) we suggest to provide a name anyway, otherwise the pattern string itself would be used to represent the filter in the UI.
63
               </documentation>
64
               <appInfo>
65
                  <meta.attribute translatable="true"/>
66
               </appInfo>
67
            </annotation>
68
         </attribute>
69
         <attribute name="description" type="string">
70
            <annotation>
71
               <documentation>
72
                  a short description for this filter
73
               </documentation>
74
               <appInfo>
75
                  <meta.attribute translatable="true"/>
76
               </appInfo>
77
            </annotation>
78
         </attribute>
79
         <attribute name="targetId" type="string">
80
            <annotation>
81
               <documentation>
82
                  the id of the target where this filter is contributed.  If this attribute is missing, then the filter will
83
be contributed to all views which use the &lt;code&gt;org.eclipse.wst.sse.ui.actions.CustomFiltersAction&lt;/code&gt;. This
84
replaces the deprecated attribute &quot;viewId&quot;.
85
               </documentation>
86
            </annotation>
87
         </attribute>
88
         <attribute name="enabled" type="boolean">
89
            <annotation>
90
               <documentation>
91
                  the filter will be enabled if this attribute is &quot;true&quot; or if this attribute is not present. Most likely the user will be able to override this setting in the UI.
92
               </documentation>
93
            </annotation>
94
         </attribute>
95
         <attribute name="pattern" type="string">
96
            <annotation>
97
               <documentation>
98
                  elements whose name matches this pattern will be hidden. This attribute is here for backward compatibility and should no longer be used. All views that allow to plug-in a filter also allow to add pattern filters directly via UI.
99
               </documentation>
100
            </annotation>
101
         </attribute>
102
         <attribute name="class" type="string">
103
            <annotation>
104
               <documentation>
105
                  the name of the class used to filter the view.  The class must extend &lt;code&gt;org.eclipse.jface.viewers.ViewerFilter&lt;/code&gt;. If this attribute is here
106
then the pattern attribute must not provided.
107
               </documentation>
108
               <appInfo>
109
                  <meta.attribute kind="java" basedOn="org.eclipse.jface.viewers.ViewerFilter"/>
110
               </appInfo>
111
            </annotation>
112
         </attribute>
113
      </complexType>
114
   </element>
115
116
   <annotation>
117
      <appInfo>
118
         <meta.section type="examples"/>
119
      </appInfo>
120
      <documentation>
121
         Works similar to javaElementFilter definition with targetId as "org.wst.sse.ui.OutlinePage".
122
         Target id can be changed for different content types to provide their own filters
123
      </documentation>
124
   </annotation>
125
126
   <annotation>
127
      <appInfo>
128
         <meta.section type="apiInfo"/>
129
      </appInfo>
130
      <documentation>
131
         
132
      </documentation>
133
   </annotation>
134
135
   <annotation>
136
      <appInfo>
137
         <meta.section type="implementation"/>
138
      </appInfo>
139
      <documentation>
140
         
141
      </documentation>
142
   </annotation>
143
144
   <annotation>
145
      <appInfo>
146
         <meta.section type="copyright"/>
147
      </appInfo>
148
      <documentation>
149
         Copyright (c) 2001, 2010 IBM Corporation and others.&lt;br&gt;
150
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
151
      </documentation>
152
   </annotation>
153
154
155
</schema>
(-)src/org/eclipse/wst/sse/ui/filter/SSECustomFiltersDialog.java (+417 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 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
package org.eclipse.wst.sse.ui.filter;
12
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
import java.util.HashSet;
16
import java.util.Iterator;
17
import java.util.List;
18
import java.util.Set;
19
import java.util.Stack;
20
import java.util.StringTokenizer;
21
22
import org.eclipse.core.runtime.Assert;
23
import org.eclipse.jface.dialogs.IDialogConstants;
24
import org.eclipse.jface.viewers.ArrayContentProvider;
25
import org.eclipse.jface.viewers.CheckStateChangedEvent;
26
import org.eclipse.jface.viewers.CheckboxTableViewer;
27
import org.eclipse.jface.viewers.ICheckStateListener;
28
import org.eclipse.jface.viewers.ILabelProvider;
29
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.ISelectionChangedListener;
31
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.eclipse.jface.viewers.LabelProvider;
33
import org.eclipse.jface.viewers.SelectionChangedEvent;
34
import org.eclipse.swt.SWT;
35
import org.eclipse.swt.events.SelectionAdapter;
36
import org.eclipse.swt.events.SelectionEvent;
37
import org.eclipse.swt.events.SelectionListener;
38
import org.eclipse.swt.graphics.Image;
39
import org.eclipse.swt.layout.GridData;
40
import org.eclipse.swt.layout.GridLayout;
41
import org.eclipse.swt.widgets.Button;
42
import org.eclipse.swt.widgets.Composite;
43
import org.eclipse.swt.widgets.Control;
44
import org.eclipse.swt.widgets.Label;
45
import org.eclipse.swt.widgets.Shell;
46
import org.eclipse.swt.widgets.Text;
47
import org.eclipse.ui.PlatformUI;
48
import org.eclipse.ui.dialogs.SelectionDialog;
49
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
50
51
52
public class SSECustomFiltersDialog extends SelectionDialog {
53
54
	private static final String SEPARATOR= ",";  //$NON-NLS-1$
55
56
	private String fViewId;
57
	private boolean fEnablePatterns;
58
	private String[] fPatterns;
59
	private String[] fEnabledFilterIds;
60
61
	private SSEFilterDescriptor[] fBuiltInFilters;
62
63
	private CheckboxTableViewer fCheckBoxList;
64
	private Button fEnableUserDefinedPatterns;
65
	private Text fUserDefinedPatterns;
66
67
	private Stack fFilterDescriptorChangeHistory;
68
69
70
	/**
71
	 * Creates a dialog to customize Java element filters.
72
	 *
73
	 * @param shell the parent shell
74
	 * @param viewId the id of the view
75
	 * @param enablePatterns <code>true</code> if pattern filters are enabled
76
	 * @param patterns the filter patterns
77
	 * @param enabledFilterIds the Ids of the enabled filters
78
	 */
79
	public SSECustomFiltersDialog(
80
			Shell shell,
81
			String viewId,
82
			boolean enablePatterns,
83
			String[] patterns,
84
			String[] enabledFilterIds) {
85
86
		super(shell);
87
		Assert.isNotNull(viewId);
88
		Assert.isNotNull(patterns);
89
		Assert.isNotNull(enabledFilterIds);
90
91
		fViewId= viewId;
92
		fPatterns= patterns;
93
		fEnablePatterns= enablePatterns;
94
		fEnabledFilterIds= enabledFilterIds;
95
96
		fBuiltInFilters= SSEFilterDescriptor.getFilterDescriptors(fViewId);
97
		fFilterDescriptorChangeHistory= new Stack();
98
	}
99
	public static final String CUSTOM_FILTERS_DIALOG= SSEUIPlugin.ID + "." + "open_custom_filters_dialog_context"; //$NON-NLS-1$
100
	protected void configureShell(Shell shell) {
101
		setTitle(SSEFilterMessages.CustomFiltersDialog_title);
102
		setMessage(SSEFilterMessages.CustomFiltersDialog_filterList_label);
103
		super.configureShell(shell);
104
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, CUSTOM_FILTERS_DIALOG);
105
	}
106
107
	/**
108
	 * Overrides method in Dialog
109
	 *
110
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
111
	 */
112
	protected Control createDialogArea(Composite parent) {
113
		initializeDialogUnits(parent);
114
		// create a composite with standard margins and spacing
115
		Composite composite= new Composite(parent, SWT.NONE);
116
		GridLayout layout= new GridLayout();
117
		layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
118
		layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
119
		layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
120
		layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
121
		composite.setLayout(layout);
122
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
123
		composite.setFont(parent.getFont());
124
		Composite group= composite;
125
126
		// Checkbox
127
		fEnableUserDefinedPatterns= new Button(group, SWT.CHECK);
128
		fEnableUserDefinedPatterns.setFocus();
129
		fEnableUserDefinedPatterns.setText(SSEFilterMessages.CustomFiltersDialog_enableUserDefinedPattern);
130
131
		// Pattern	field
132
		fUserDefinedPatterns= new Text(group, SWT.SINGLE | SWT.BORDER);
133
		GridData  data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
134
		data.widthHint= convertWidthInCharsToPixels(59);
135
		fUserDefinedPatterns.setLayoutData(data);
136
		String patterns= convertToString(fPatterns, SEPARATOR);
137
		fUserDefinedPatterns.setText(patterns);
138
		SWTUtil.setAccessibilityText(fUserDefinedPatterns, SSEFilterMessages.CustomFiltersDialog_name_filter_pattern_description);
139
140
		// Info text
141
		final Label info= new Label(group, SWT.LEFT);
142
		info.setText(SSEFilterMessages.CustomFiltersDialog_patternInfo);
143
144
		// Enabling / disabling of pattern group
145
		fEnableUserDefinedPatterns.setSelection(fEnablePatterns);
146
		fUserDefinedPatterns.setEnabled(fEnablePatterns);
147
		info.setEnabled(fEnablePatterns);
148
		fEnableUserDefinedPatterns.addSelectionListener(new SelectionAdapter() {
149
			public void widgetSelected(SelectionEvent e) {
150
				boolean state= fEnableUserDefinedPatterns.getSelection();
151
				fUserDefinedPatterns.setEnabled(state);
152
				info.setEnabled(fEnableUserDefinedPatterns.getSelection());
153
				if (state)
154
					fUserDefinedPatterns.setFocus();
155
			}
156
		});
157
158
		// Filters provided by extension point
159
		if (fBuiltInFilters.length > 0)
160
			createCheckBoxList(group);
161
162
		applyDialogFont(parent);
163
		return parent;
164
	}
165
166
	private void createCheckBoxList(Composite parent) {
167
		// Filler
168
		new Label(parent, SWT.NONE);
169
170
		Label info= new Label(parent, SWT.LEFT);
171
		info.setText(SSEFilterMessages.CustomFiltersDialog_filterList_label);
172
173
		fCheckBoxList= CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
174
		GridData data= new GridData(GridData.FILL_BOTH);
175
		data.heightHint= fCheckBoxList.getTable().getItemHeight() * 10;
176
		fCheckBoxList.getTable().setLayoutData(data);
177
178
		fCheckBoxList.setLabelProvider(createLabelPrivder());
179
		fCheckBoxList.setContentProvider(new ArrayContentProvider());
180
		Arrays.sort(fBuiltInFilters);
181
		fCheckBoxList.setInput(fBuiltInFilters);
182
		setInitialSelections(getEnabledFilterDescriptors());
183
184
		List initialSelection= getInitialElementSelections();
185
		if (initialSelection != null && !initialSelection.isEmpty())
186
			checkInitialSelections();
187
188
		// Description
189
		info= new Label(parent, SWT.LEFT);
190
		info.setText(SSEFilterMessages.CustomFiltersDialog_description_label);
191
		final Text description= new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
192
		data = new GridData(GridData.FILL_HORIZONTAL);
193
		data.heightHint= convertHeightInCharsToPixels(3);
194
		description.setLayoutData(data);
195
		fCheckBoxList.addSelectionChangedListener(new ISelectionChangedListener() {
196
			public void selectionChanged(SelectionChangedEvent event) {
197
				ISelection selection= event.getSelection();
198
				if (selection instanceof IStructuredSelection) {
199
					Object selectedElement= ((IStructuredSelection)selection).getFirstElement();
200
					if (selectedElement instanceof SSEFilterDescriptor)
201
						description.setText(((SSEFilterDescriptor)selectedElement).getDescription());
202
				}
203
			}
204
		});
205
		fCheckBoxList.addCheckStateListener(new ICheckStateListener() {
206
			/*
207
			 * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
208
			 */
209
			public void checkStateChanged(CheckStateChangedEvent event) {
210
				Object element= event.getElement();
211
				if (element instanceof SSEFilterDescriptor) {
212
					// renew if already touched
213
					if (fFilterDescriptorChangeHistory.contains(element))
214
						fFilterDescriptorChangeHistory.remove(element);
215
					fFilterDescriptorChangeHistory.push(element);
216
				}
217
			}});
218
219
		addSelectionButtons(parent);
220
	}
221
222
	private void addSelectionButtons(Composite composite) {
223
		Composite buttonComposite= new Composite(composite, SWT.RIGHT);
224
		GridLayout layout= new GridLayout();
225
		layout.numColumns= 2;
226
		buttonComposite.setLayout(layout);
227
		GridData data= new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
228
		data.grabExcessHorizontalSpace= true;
229
		composite.setData(data);
230
231
		// Select All button
232
		String label= SSEFilterMessages.CustomFiltersDialog_SelectAllButton_label;
233
		Button selectButton= createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, label, false);
234
		SWTUtil.setButtonDimensionHint(selectButton);
235
		SelectionListener listener= new SelectionAdapter() {
236
			public void widgetSelected(SelectionEvent e) {
237
				fCheckBoxList.setAllChecked(true);
238
				fFilterDescriptorChangeHistory.clear();
239
				for (int i= 0; i < fBuiltInFilters.length; i++)
240
					fFilterDescriptorChangeHistory.push(fBuiltInFilters[i]);
241
			}
242
		};
243
		selectButton.addSelectionListener(listener);
244
245
		// De-select All button
246
		label= SSEFilterMessages.CustomFiltersDialog_DeselectAllButton_label;
247
		Button deselectButton= createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, label, false);
248
		SWTUtil.setButtonDimensionHint(deselectButton);
249
		listener= new SelectionAdapter() {
250
			public void widgetSelected(SelectionEvent e) {
251
				fCheckBoxList.setAllChecked(false);
252
				fFilterDescriptorChangeHistory.clear();
253
				for (int i= 0; i < fBuiltInFilters.length; i++)
254
					fFilterDescriptorChangeHistory.push(fBuiltInFilters[i]);
255
			}
256
		};
257
		deselectButton.addSelectionListener(listener);
258
	}
259
260
	private void checkInitialSelections() {
261
		Iterator itemsToCheck= getInitialElementSelections().iterator();
262
		while (itemsToCheck.hasNext())
263
			fCheckBoxList.setChecked(itemsToCheck.next(),true);
264
	}
265
266
	protected void okPressed() {
267
		if (fBuiltInFilters != null) {
268
			ArrayList result= new ArrayList();
269
			for (int i= 0; i < fBuiltInFilters.length; ++i) {
270
				if (fCheckBoxList.getChecked(fBuiltInFilters[i]))
271
					result.add(fBuiltInFilters[i]);
272
			}
273
			setResult(result);
274
		}
275
		super.okPressed();
276
	}
277
278
	private ILabelProvider createLabelPrivder() {
279
		return
280
			new LabelProvider() {
281
				public Image getImage(Object element) {
282
					return null;
283
				}
284
				public String getText(Object element) {
285
					if (element instanceof SSEFilterDescriptor)
286
						return ((SSEFilterDescriptor)element).getName();
287
					else
288
						return null;
289
				}
290
			};
291
	}
292
293
	// ---------- result handling ----------
294
295
	protected void setResult(List newResult) {
296
		super.setResult(newResult);
297
		if (fUserDefinedPatterns.getText().length() > 0) {
298
			fEnablePatterns= fEnableUserDefinedPatterns.getSelection();
299
			fPatterns= convertFromString(fUserDefinedPatterns.getText(), SEPARATOR);
300
		} else {
301
			fEnablePatterns= false;
302
			fPatterns= new String[0];
303
		}
304
	}
305
306
307
	/**
308
	 * @return the patterns which have been entered by the user
309
	 */
310
	public String[] getUserDefinedPatterns() {
311
		return fPatterns;
312
	}
313
314
	/**
315
	 * @return the Ids of the enabled built-in filters
316
	 */
317
	public String[] getEnabledFilterIds() {
318
		Object[] result= getResult();
319
		Set enabledIds= new HashSet(result.length);
320
		for (int i= 0; i < result.length; i++)
321
			enabledIds.add(((SSEFilterDescriptor)result[i]).getId());
322
		return (String[]) enabledIds.toArray(new String[enabledIds.size()]);
323
	}
324
325
	/**
326
	 * @return <code>true</code> if the user-defined patterns are disabled
327
	 */
328
	public boolean areUserDefinedPatternsEnabled() {
329
		return fEnablePatterns;
330
	}
331
332
	/**
333
	 * @return a stack with the filter descriptor check history
334
	 * @since 3.0
335
	 */
336
	public Stack getFilterDescriptorChangeHistory() {
337
		return fFilterDescriptorChangeHistory;
338
	}
339
340
	private SSEFilterDescriptor[] getEnabledFilterDescriptors() {
341
		SSEFilterDescriptor[] filterDescs= fBuiltInFilters;
342
		List result= new ArrayList(filterDescs.length);
343
		List enabledFilterIds= Arrays.asList(fEnabledFilterIds);
344
		for (int i= 0; i < filterDescs.length; i++) {
345
			String id= filterDescs[i].getId();
346
			if (enabledFilterIds.contains(id))
347
				result.add(filterDescs[i]);
348
		}
349
		return (SSEFilterDescriptor[])result.toArray(new SSEFilterDescriptor[result.size()]);
350
	}
351
352
353
	public static String[] convertFromString(String patterns, String separator) {
354
		StringTokenizer tokenizer= new StringTokenizer(patterns, separator, true);
355
		int tokenCount= tokenizer.countTokens();
356
		List result= new ArrayList(tokenCount);
357
		boolean escape= false;
358
		boolean append= false;
359
		while (tokenizer.hasMoreTokens()) {
360
			String token= tokenizer.nextToken().trim();
361
			if (separator.equals(token)) {
362
				if (!escape)
363
					escape= true;
364
				else {
365
					addPattern(result, separator);
366
					append= true;
367
				}
368
			} else  {
369
				if (!append)
370
 					result.add(token);
371
				else
372
					addPattern(result, token);
373
				append= false;
374
				escape= false;
375
			}
376
		}
377
		return (String[])result.toArray(new String[result.size()]);
378
	}
379
380
	private static void addPattern(List list, String pattern) {
381
		if (list.isEmpty())
382
			list.add(pattern);
383
		else {
384
			int index= list.size() - 1;
385
			list.set(index, ((String)list.get(index)) + pattern);
386
		}
387
	}
388
389
	public static String convertToString(String[] patterns, String separator) {
390
		int length= patterns.length;
391
		StringBuffer strBuf= new StringBuffer();
392
		if (length > 0)
393
			strBuf.append(escapeSeparator(patterns[0], separator));
394
		else
395
			return ""; //$NON-NLS-1$
396
		int i= 1;
397
		while (i < length) {
398
			strBuf.append(separator);
399
			strBuf.append(" "); //$NON-NLS-1$
400
			strBuf.append(escapeSeparator(patterns[i++], separator));
401
		}
402
		return strBuf.toString();
403
	}
404
405
	private static String escapeSeparator(String pattern, String separator) {
406
		int length= pattern.length();
407
		StringBuffer buf= new StringBuffer(length);
408
		for (int i= 0; i < length; i++) {
409
			char ch= pattern.charAt(i);
410
			if (separator.equals(String.valueOf(ch)))
411
				buf.append(ch);
412
			buf.append(ch);
413
		}
414
		return buf.toString();
415
416
	}
417
}
(-)src/org/eclipse/wst/sse/ui/filter/SSEFilterDescriptor.java (+290 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 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
package org.eclipse.wst.sse.ui.filter;
12
13
import java.util.ArrayList;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Set;
17
18
import com.ibm.icu.text.Collator;
19
20
import org.eclipse.core.runtime.Assert;
21
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IExtensionRegistry;
23
import org.eclipse.core.runtime.ISafeRunnable;
24
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.SafeRunner;
26
27
import org.eclipse.jface.util.SafeRunnable;
28
import org.eclipse.jface.viewers.ViewerFilter;
29
30
import org.eclipse.ui.IPluginContribution;
31
import org.eclipse.ui.activities.WorkbenchActivityHelper;
32
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
33
34
35
36
/**
37
 * Represents a custom filter which is provided by the
38
 * "org.eclipse.jdt.ui.javaElementFilters" extension point.
39
 *
40
 * since 2.0
41
 */
42
public class SSEFilterDescriptor implements Comparable, IPluginContribution {
43
44
	private static String PATTERN_FILTER_ID_PREFIX= "_patternFilterId_"; //$NON-NLS-1$
45
46
47
	private static final String EXTENSION_POINT_NAME= "sseElementFilter"; //$NON-NLS-1$
48
49
	private static final String FILTER_TAG= "filter"; //$NON-NLS-1$
50
51
	private static final String PATTERN_ATTRIBUTE= "pattern"; //$NON-NLS-1$
52
	private static final String ID_ATTRIBUTE= "id"; //$NON-NLS-1$
53
	/**
54
	 * @deprecated as of 3.0 use {@link SSEFilterDescriptor#TARGET_ID_ATTRIBUTE}
55
	 */
56
	private static final String VIEW_ID_ATTRIBUTE= "viewId"; //$NON-NLS-1$
57
	private static final String TARGET_ID_ATTRIBUTE= "targetId"; //$NON-NLS-1$
58
	private static final String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
59
	private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$
60
	private static final String ENABLED_ATTRIBUTE= "enabled"; //$NON-NLS-1$
61
	private static final String DESCRIPTION_ATTRIBUTE= "description"; //$NON-NLS-1$
62
	/**
63
	 * @deprecated	use "enabled" instead
64
	 */
65
	private static final String SELECTED_ATTRIBUTE= "selected"; //$NON-NLS-1$
66
67
	private static SSEFilterDescriptor[] fgFilterDescriptors;
68
69
70
	private IConfigurationElement fElement;
71
72
	/**
73
	 * Returns all contributed Java element filters.
74
	 * @return all contributed Java element filters
75
	 */
76
	public static SSEFilterDescriptor[] getFilterDescriptors() {
77
		if (fgFilterDescriptors == null) {
78
			IExtensionRegistry registry= Platform.getExtensionRegistry();
79
			IConfigurationElement[] elements= registry.getConfigurationElementsFor(SSEUIPlugin.ID, EXTENSION_POINT_NAME);
80
			fgFilterDescriptors= createFilterDescriptors(elements);
81
		}
82
		return fgFilterDescriptors;
83
	}
84
	/**
85
	 * Returns all Java element filters which
86
	 * are contributed to the given view.
87
	 * @param targetId the target id
88
	 * @return all contributed Java element filters for the given view
89
	 */
90
	public static SSEFilterDescriptor[] getFilterDescriptors(String targetId) {
91
		SSEFilterDescriptor[] filterDescs= SSEFilterDescriptor.getFilterDescriptors();
92
		List result= new ArrayList(filterDescs.length);
93
		for (int i= 0; i < filterDescs.length; i++) {
94
			String tid= filterDescs[i].getTargetId();
95
			if (WorkbenchActivityHelper.filterItem(filterDescs[i]))
96
				continue;
97
			if (tid == null || tid.equals(targetId))
98
				result.add(filterDescs[i]);
99
		}
100
		return (SSEFilterDescriptor[])result.toArray(new SSEFilterDescriptor[result.size()]);
101
	}
102
103
	/**
104
	 * Creates a new filter descriptor for the given configuration element.
105
	 * @param element configuration element
106
	 */
107
	private SSEFilterDescriptor(IConfigurationElement element) {
108
		fElement= element;
109
		// it is either a pattern filter or a custom filter
110
		Assert.isTrue(isPatternFilter() ^ isCustomFilter(), "An extension for extension-point org.eclipse.jdt.ui.javaElementFilters does not specify a correct filter"); //$NON-NLS-1$
111
		Assert.isNotNull(getId(), "An extension for extension-point org.eclipse.jdt.ui.javaElementFilters does not provide a valid ID"); //$NON-NLS-1$
112
		Assert.isNotNull(getName(), "An extension for extension-point org.eclipse.jdt.ui.javaElementFilters does not provide a valid name"); //$NON-NLS-1$
113
	}
114
115
	/**
116
	 * Creates a new <code>ViewerFilter</code>.
117
	 * This method is only valid for viewer filters.
118
	 * @return a new <code>ViewerFilter</code>
119
	 */
120
	public ViewerFilter createViewerFilter() {
121
		if (!isCustomFilter())
122
			return null;
123
124
		final ViewerFilter[] result= new ViewerFilter[1];
125
		String message = SSEFilterMessages.FilterDescriptor_filterCreationError_message;
126
		ISafeRunnable code= new SafeRunnable(message) {
127
			/*
128
			 * @see org.eclipse.core.runtime.ISafeRunnable#run()
129
			 */
130
			public void run() throws Exception {
131
				result[0]= (ViewerFilter)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
132
			}
133
134
		};
135
		SafeRunner.run(code);
136
		return result[0];
137
	}
138
139
	//---- XML Attribute accessors ---------------------------------------------
140
141
	/**
142
	 * Returns the filter's id.
143
	 * <p>
144
	 * This attribute is mandatory for custom filters.
145
	 * The ID for pattern filters is
146
	 * PATTERN_FILTER_ID_PREFIX plus the pattern itself.
147
	 * </p>
148
	 * @return the filter id
149
	 */
150
	public String getId() {
151
		if (isPatternFilter()) {
152
			String targetId= getTargetId();
153
			if (targetId == null)
154
				return PATTERN_FILTER_ID_PREFIX + getPattern();
155
			else
156
				return targetId + PATTERN_FILTER_ID_PREFIX + getPattern();
157
		} else
158
			return fElement.getAttribute(ID_ATTRIBUTE);
159
	}
160
161
	/**
162
	 * Returns the filter's name.
163
	 * <p>
164
	 * If the name of a pattern filter is missing
165
	 * then the pattern is used as its name.
166
	 * </p>
167
	 * @return the filter's name
168
	 */
169
	public String getName() {
170
		String name= fElement.getAttribute(NAME_ATTRIBUTE);
171
		if (name == null && isPatternFilter())
172
			name= getPattern();
173
		return name;
174
	}
175
176
	/**
177
	 * Returns the filter's pattern.
178
	 *
179
	 * @return the pattern string or <code>null</code> if it's not a pattern filter
180
	 */
181
	public String getPattern() {
182
		return fElement.getAttribute(PATTERN_ATTRIBUTE);
183
	}
184
185
	/**
186
	 * Returns the filter's viewId.
187
	 *
188
	 * @return the view ID or <code>null</code> if the filter is for all views
189
	 * @since 3.0
190
	 */
191
	public String getTargetId() {
192
		String tid= fElement.getAttribute(TARGET_ID_ATTRIBUTE);
193
194
		if (tid != null)
195
			return tid;
196
197
		// Backwards compatibility code
198
		return fElement.getAttribute(VIEW_ID_ATTRIBUTE);
199
200
	}
201
202
	/**
203
	 * Returns the filter's description.
204
	 *
205
	 * @return the description or <code>null</code> if no description is provided
206
	 */
207
	public String getDescription() {
208
		String description= fElement.getAttribute(DESCRIPTION_ATTRIBUTE);
209
		if (description == null)
210
			description= ""; //$NON-NLS-1$
211
		return description;
212
	}
213
214
	/**
215
	 * @return <code>true</code> if this filter is a custom filter.
216
	 */
217
	public boolean isPatternFilter() {
218
		return getPattern() != null;
219
	}
220
221
	/**
222
	 * @return <code>true</code> if this filter is a pattern filter.
223
	 */
224
	public boolean isCustomFilter() {
225
		return fElement.getAttribute(CLASS_ATTRIBUTE) != null;
226
	}
227
228
	/**
229
	 * Returns <code>true</code> if the filter
230
	 * is initially enabled.
231
	 *
232
	 * This attribute is optional and defaults to <code>true</code>.
233
	 * @return returns <code>true</code> if the filter is initially enabled
234
	 */
235
	public boolean isEnabled() {
236
		String strVal= fElement.getAttribute(ENABLED_ATTRIBUTE);
237
		if (strVal == null)
238
			// backward compatibility
239
			strVal= fElement.getAttribute(SELECTED_ATTRIBUTE);
240
		return strVal == null || Boolean.valueOf(strVal).booleanValue();
241
	}
242
243
	/*
244
	 * Implements a method from IComparable
245
	 */
246
	public int compareTo(Object o) {
247
		if (o instanceof SSEFilterDescriptor)
248
			return Collator.getInstance().compare(getName(), ((SSEFilterDescriptor)o).getName());
249
		else
250
			return Integer.MIN_VALUE;
251
	}
252
253
	//---- initialization ---------------------------------------------------
254
255
	/**
256
	 * Creates the filter descriptors.
257
	 * @param elements the configuration elements
258
	 * @return new filter descriptors
259
	 */
260
	private static SSEFilterDescriptor[] createFilterDescriptors(IConfigurationElement[] elements) {
261
		List result= new ArrayList(5);
262
		Set descIds= new HashSet(5);
263
		for (int i= 0; i < elements.length; i++) {
264
			final IConfigurationElement element= elements[i];
265
			if (FILTER_TAG.equals(element.getName())) {
266
267
				final SSEFilterDescriptor[] desc= new SSEFilterDescriptor[1];
268
				SafeRunner.run(new SafeRunnable(SSEFilterMessages.FilterDescriptor_filterDescriptionCreationError_message) {
269
					public void run() throws Exception {
270
						desc[0]= new SSEFilterDescriptor(element);
271
					}
272
				});
273
274
				if (desc[0] != null && !descIds.contains(desc[0].getId())) {
275
					result.add(desc[0]);
276
					descIds.add(desc[0].getId());
277
				}
278
			}
279
		}
280
		return (SSEFilterDescriptor[])result.toArray(new SSEFilterDescriptor[result.size()]);
281
	}
282
283
	public String getLocalId() {
284
		return fElement.getAttribute(ID_ATTRIBUTE);
285
	}
286
287
    public String getPluginId() {
288
        return fElement.getContributor().getName();
289
    }
290
}
(-)src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.java (+38 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 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
package org.eclipse.wst.sse.ui.filter;
12
13
import org.eclipse.osgi.util.NLS;
14
15
public final class SSEFilterMessages extends NLS {
16
17
	private static final String BUNDLE_NAME= "org.eclipse.wst.sse.ui.filter.SSEFilterMessages";//$NON-NLS-1$
18
19
	private SSEFilterMessages() {
20
		// Do not instantiate
21
	}
22
23
	public static String CustomFiltersDialog_title;
24
	public static String CustomFiltersDialog_patternInfo;
25
	public static String CustomFiltersDialog_enableUserDefinedPattern;
26
	public static String CustomFiltersDialog_filterList_label;
27
	public static String CustomFiltersDialog_description_label;
28
	public static String CustomFiltersDialog_SelectAllButton_label;
29
	public static String CustomFiltersDialog_DeselectAllButton_label;
30
	public static String CustomFiltersDialog_name_filter_pattern_description;
31
	public static String OpenCustomFiltersDialogAction_text;
32
	public static String FilterDescriptor_filterDescriptionCreationError_message;
33
	public static String FilterDescriptor_filterCreationError_message;
34
35
	static {
36
		NLS.initializeMessages(BUNDLE_NAME, SSEFilterMessages.class);
37
	}
38
}
(-)src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.properties (+24 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 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
CustomFiltersDialog_title= Java Element Filters
13
CustomFiltersDialog_patternInfo= The patterns are separated by comma, where\n* = any string, ? = any character, ,, = ,
14
CustomFiltersDialog_enableUserDefinedPattern= &Name filter patterns (matching names will be hidden):
15
CustomFiltersDialog_filterList_label= S&elect the elements to exclude from the view:
16
CustomFiltersDialog_description_label= Filter description:
17
CustomFiltersDialog_SelectAllButton_label= &Select All
18
CustomFiltersDialog_DeselectAllButton_label= &Deselect All
19
CustomFiltersDialog_name_filter_pattern_description=Name filter patterns. The patterns are separated by comma, where star is any string
20
21
OpenCustomFiltersDialogAction_text= &Filters...
22
23
FilterDescriptor_filterDescriptionCreationError_message= One of the extensions for extension-point org.eclipse.wst.sse.ui.sseElementFilters is incorrect.
24
FilterDescriptor_filterCreationError_message= The org.eclipse.wst.sse.ui.sssElementFilters plug-in extension "{0}" specifies a viewer filter class which does not exist.
(-)src/org/eclipse/wst/sse/ui/filter/SSENamePatternFilter.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 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
package org.eclipse.wst.sse.ui.filter;
12
13
import org.eclipse.jface.viewers.Viewer;
14
import org.eclipse.jface.viewers.ViewerFilter;
15
import org.w3c.dom.Node;
16
17
/**
18
 * The NamePatternFilter selects the elements which
19
 * match the given string patterns.
20
 * <p>
21
 * The following characters have special meaning:
22
 *   ? => any character
23
 *   * => any string
24
 * </p>
25
 *
26
 * @since 2.0
27
 */
28
public class SSENamePatternFilter extends ViewerFilter {
29
	private String[] fPatterns;
30
	private SSEStringMatcher[] fMatchers;
31
32
33
	/**
34
	 * Gets the patterns for the receiver.
35
	 * @return returns the patterns to be filtered for
36
	 */
37
	public String[] getPatterns() {
38
		return fPatterns;
39
	}
40
41
42
	/* (non-Javadoc)
43
	 * Method declared on ViewerFilter.
44
	 */
45
	public boolean select(Viewer viewer, Object parentElement, Object element) {
46
		if (getPatterns().length == 0) {
47
			return true;
48
		}
49
		String matchName= null;
50
		if (element instanceof Node){
51
			matchName =((Node)element).getNodeName();
52
		}
53
		if (matchName != null && matchName.length() > 0) {
54
			String[] fPatterns = getPatterns();
55
			for (int i = 0; i < fPatterns.length; i++) {
56
				if (new SSEStringMatcher(fPatterns[i], true, false).match(matchName))
57
					return false;
58
			}
59
			return true;
60
		}
61
		return true;
62
	}
63
64
	/**
65
	 * Sets the patterns to filter out for the receiver.
66
	 * <p>
67
	 * The following characters have special meaning:
68
	 *   ? => any character
69
	 *   * => any string
70
	 * </p>
71
	 * @param newPatterns the new patterns
72
	 */
73
	public void setPatterns(String[] newPatterns) {
74
		fPatterns = newPatterns;
75
		fMatchers = new SSEStringMatcher[newPatterns.length];
76
		for (int i = 0; i < newPatterns.length; i++) {
77
			//Reset the matchers to prevent constructor overhead
78
			fMatchers[i]= new SSEStringMatcher(newPatterns[i], true, false);
79
		}
80
	}
81
}
(-)src/org/eclipse/wst/sse/ui/filter/SSEStringMatcher.java (+384 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 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
package org.eclipse.wst.sse.ui.filter;
12
13
import java.util.Vector;
14
15
/**
16
 * A string pattern matcher. Supports '*' and '?' wildcards.
17
 */
18
public class SSEStringMatcher {
19
	protected String fPattern;
20
	protected int fLength; // pattern length
21
	protected boolean fIgnoreWildCards;
22
	protected boolean fIgnoreCase;
23
	protected boolean fHasLeadingStar;
24
	protected boolean fHasTrailingStar;
25
	protected String fSegments[]; //the given pattern is split into * separated segments
26
27
	/* boundary value beyond which we don't need to search in the text */
28
	protected int fBound= 0;
29
30
31
	protected static final char fSingleWildCard= '\u0000';
32
33
	public static class Position {
34
		int start; //inclusive
35
		int end; //exclusive
36
		public Position(int start, int end) {
37
			this.start= start;
38
			this.end= end;
39
		}
40
		public int getStart() {
41
			return start;
42
		}
43
		public int getEnd() {
44
			return end;
45
		}
46
	}
47
	/**
48
	 * StringMatcher constructor takes in a String object that is a simple
49
	 * pattern. The pattern may contain '*' for 0 and many characters and
50
	 * '?' for exactly one character.
51
	 *
52
	 * Literal '*' and '?' characters must be escaped in the pattern
53
	 * e.g., "\*" means literal "*", etc.
54
	 *
55
	 * Escaping any other character (including the escape character itself),
56
	 * just results in that character in the pattern.
57
	 * e.g., "\a" means "a" and "\\" means "\"
58
	 *
59
	 * If invoking the StringMatcher with string literals in Java, don't forget
60
	 * escape characters are represented by "\\".
61
	 *
62
	 * @param pattern the pattern to match text against
63
	 * @param ignoreCase if true, case is ignored
64
	 * @param ignoreWildCards if true, wild cards and their escape sequences are ignored
65
	 * 		  (everything is taken literally).
66
	 */
67
	public SSEStringMatcher(String pattern, boolean ignoreCase, boolean ignoreWildCards) {
68
		if (pattern == null)
69
			throw new IllegalArgumentException();
70
		fIgnoreCase= ignoreCase;
71
		fIgnoreWildCards= ignoreWildCards;
72
		fPattern= pattern;
73
		fLength= pattern.length();
74
75
		if (fIgnoreWildCards) {
76
			parseNoWildCards();
77
		} else {
78
			parseWildCards();
79
		}
80
	}
81
	/**
82
	 * Find the first occurrence of the pattern between <code>start</code)(inclusive)
83
	 * and <code>end</code>(exclusive).
84
	 * @param text the String object to search in
85
	 * @param start the starting index of the search range, inclusive
86
	 * @param end the ending index of the search range, exclusive
87
	 * @return an <code>StringMatcher.Position</code> object that keeps the starting
88
	 * (inclusive) and ending positions (exclusive) of the first occurrence of the
89
	 * pattern in the specified range of the text; return null if not found or subtext
90
	 * is empty (start==end). A pair of zeros is returned if pattern is empty string
91
	 * Note that for pattern like "*abc*" with leading and trailing stars, position of "abc"
92
	 * is returned. For a pattern like"*??*" in text "abcdf", (1,3) is returned
93
	 */
94
	public SSEStringMatcher.Position find(String text, int start, int end) {
95
		if (text == null)
96
			throw new IllegalArgumentException();
97
98
		int tlen= text.length();
99
		if (start < 0)
100
			start= 0;
101
		if (end > tlen)
102
			end= tlen;
103
		if (end < 0 ||start >= end )
104
			return null;
105
		if (fLength == 0)
106
			return new Position(start, start);
107
		if (fIgnoreWildCards) {
108
			int x= posIn(text, start, end);
109
			if (x < 0)
110
				return null;
111
			return new Position(x, x+fLength);
112
		}
113
114
		int segCount= fSegments.length;
115
		if (segCount == 0)//pattern contains only '*'(s)
116
			return new Position (start, end);
117
118
		int curPos= start;
119
		int matchStart= -1;
120
		int i;
121
		for (i= 0; i < segCount && curPos < end; ++i) {
122
			String current= fSegments[i];
123
			int nextMatch= regExpPosIn(text, curPos, end, current);
124
			if (nextMatch < 0 )
125
				return null;
126
			if(i == 0)
127
				matchStart= nextMatch;
128
			curPos= nextMatch + current.length();
129
		}
130
		if (i < segCount)
131
			return null;
132
		return new Position(matchStart, curPos);
133
	}
134
	/**
135
	 * match the given <code>text</code> with the pattern
136
	 * @return true if matched eitherwise false
137
	 * @param text a String object
138
	 */
139
	public boolean match(String text) {
140
		return match(text, 0, text.length());
141
	}
142
	/**
143
	 * Given the starting (inclusive) and the ending (exclusive) positions in the
144
	 * <code>text</code>, determine if the given substring matches with aPattern
145
	 * @return true if the specified portion of the text matches the pattern
146
	 * @param text a String object that contains the substring to match
147
	 * @param start marks the starting position (inclusive) of the substring
148
	 * @param end marks the ending index (exclusive) of the substring
149
	 */
150
	public boolean match(String text, int start, int end) {
151
		if (null == text)
152
			throw new IllegalArgumentException();
153
154
		if (start > end)
155
			return false;
156
157
		if (fIgnoreWildCards)
158
			return (end - start == fLength) && fPattern.regionMatches(fIgnoreCase, 0, text, start, fLength);
159
		int segCount= fSegments.length;
160
		if (segCount == 0 && (fHasLeadingStar || fHasTrailingStar))  // pattern contains only '*'(s)
161
			return true;
162
		if (start == end)
163
			return fLength == 0;
164
		if (fLength == 0)
165
			return start == end;
166
167
		int tlen= text.length();
168
		if (start < 0)
169
			start= 0;
170
		if (end > tlen)
171
			end= tlen;
172
173
		int tCurPos= start;
174
		int bound= end - fBound;
175
		if ( bound < 0)
176
			return false;
177
		int i=0;
178
		String current= fSegments[i];
179
		int segLength= current.length();
180
181
		/* process first segment */
182
		if (!fHasLeadingStar){
183
			if(!regExpRegionMatches(text, start, current, 0, segLength)) {
184
				return false;
185
			} else {
186
				++i;
187
				tCurPos= tCurPos + segLength;
188
			}
189
		}
190
		if ((fSegments.length == 1) && (!fHasLeadingStar) && (!fHasTrailingStar)) {
191
			// only one segment to match, no wildcards specified
192
			return tCurPos == end;
193
		}
194
		/* process middle segments */
195
		while (i < segCount) {
196
			current= fSegments[i];
197
			int currentMatch;
198
			int k= current.indexOf(fSingleWildCard);
199
			if (k < 0) {
200
				currentMatch= textPosIn(text, tCurPos, end, current);
201
				if (currentMatch < 0)
202
					return false;
203
			} else {
204
				currentMatch= regExpPosIn(text, tCurPos, end, current);
205
				if (currentMatch < 0)
206
					return false;
207
			}
208
			tCurPos= currentMatch + current.length();
209
			i++;
210
		}
211
212
		/* process final segment */
213
		if (!fHasTrailingStar && tCurPos != end) {
214
			int clen= current.length();
215
			return regExpRegionMatches(text, end - clen, current, 0, clen);
216
		}
217
		return i == segCount ;
218
	}
219
220
	/**
221
	 * This method parses the given pattern into segments seperated by wildcard '*' characters.
222
	 * Since wildcards are not being used in this case, the pattern consists of a single segment.
223
	 */
224
	private void parseNoWildCards() {
225
		fSegments= new String[1];
226
		fSegments[0]= fPattern;
227
		fBound= fLength;
228
	}
229
	/**
230
	 * Parses the given pattern into segments seperated by wildcard '*' characters.
231
	 */
232
	private void parseWildCards() {
233
		if(fPattern.startsWith("*"))//$NON-NLS-1$
234
			fHasLeadingStar= true;
235
		if(fPattern.endsWith("*")) {//$NON-NLS-1$
236
			/* make sure it's not an escaped wildcard */
237
			if (fLength > 1 && fPattern.charAt(fLength - 2) != '\\') {
238
				fHasTrailingStar= true;
239
			}
240
		}
241
242
		Vector temp= new Vector();
243
244
		int pos= 0;
245
		StringBuffer buf= new StringBuffer();
246
		while (pos < fLength) {
247
			char c= fPattern.charAt(pos++);
248
			switch (c) {
249
				case '\\':
250
					if (pos >= fLength) {
251
						buf.append(c);
252
					} else {
253
						char next= fPattern.charAt(pos++);
254
						/* if it's an escape sequence */
255
						if (next == '*' || next == '?' || next == '\\') {
256
							buf.append(next);
257
						} else {
258
							/* not an escape sequence, just insert literally */
259
							buf.append(c);
260
							buf.append(next);
261
						}
262
					}
263
				break;
264
				case '*':
265
					if (buf.length() > 0) {
266
						/* new segment */
267
						temp.addElement(buf.toString());
268
						fBound += buf.length();
269
						buf.setLength(0);
270
					}
271
				break;
272
				case '?':
273
					/* append special character representing single match wildcard */
274
					buf.append(fSingleWildCard);
275
				break;
276
				default:
277
					buf.append(c);
278
			}
279
		}
280
281
		/* add last buffer to segment list */
282
		if (buf.length() > 0) {
283
			temp.addElement(buf.toString());
284
			fBound += buf.length();
285
		}
286
287
		fSegments= new String[temp.size()];
288
		temp.copyInto(fSegments);
289
	}
290
	/**
291
	 * @param text a string which contains no wildcard
292
	 * @param start the starting index in the text for search, inclusive
293
	 * @param end the stopping point of search, exclusive
294
	 * @return the starting index in the text of the pattern , or -1 if not found
295
	 */
296
	protected int posIn(String text, int start, int end) {//no wild card in pattern
297
		int max= end - fLength;
298
299
		if (!fIgnoreCase) {
300
			int i= text.indexOf(fPattern, start);
301
			if (i == -1 || i > max)
302
				return -1;
303
			return i;
304
		}
305
306
		for (int i= start; i <= max; ++i) {
307
			if (text.regionMatches(true, i, fPattern, 0, fLength))
308
				return i;
309
		}
310
311
		return -1;
312
	}
313
	/**
314
	 * @param text a simple regular expression that may only contain '?'(s)
315
	 * @param start the starting index in the text for search, inclusive
316
	 * @param end the stopping point of search, exclusive
317
	 * @param p a simple regular expression that may contains '?'
318
	 * @return the starting index in the text of the pattern , or -1 if not found
319
	 */
320
	protected int regExpPosIn(String text, int start, int end, String p) {
321
		int plen= p.length();
322
323
		int max= end - plen;
324
		for (int i= start; i <= max; ++i) {
325
			if (regExpRegionMatches(text, i, p, 0, plen))
326
				return i;
327
		}
328
		return -1;
329
	}
330
331
332
	protected boolean regExpRegionMatches(String text, int tStart, String p, int pStart, int plen) {
333
		while (plen-- > 0) {
334
			char tchar= text.charAt(tStart++);
335
			char pchar= p.charAt(pStart++);
336
337
			/* process wild cards */
338
			if (!fIgnoreWildCards) {
339
				/* skip single wild cards */
340
				if (pchar == fSingleWildCard) {
341
					continue;
342
				}
343
			}
344
			if (pchar == tchar)
345
				continue;
346
			if (fIgnoreCase) {
347
				if (Character.toUpperCase(tchar) == Character.toUpperCase(pchar))
348
					continue;
349
				// comparing after converting to upper case doesn't handle all cases;
350
				// also compare after converting to lower case
351
				if (Character.toLowerCase(tchar) == Character.toLowerCase(pchar))
352
					continue;
353
			}
354
			return false;
355
		}
356
		return true;
357
	}
358
	/**
359
	 * @param text the string to match
360
	 * @param start the starting index in the text for search, inclusive
361
	 * @param end the stopping point of search, exclusive
362
	 * @param p a string that has no wildcard
363
	 * @return the starting index in the text of the pattern , or -1 if not found
364
	 */
365
	protected int textPosIn(String text, int start, int end, String p) {
366
367
		int plen= p.length();
368
		int max= end - plen;
369
370
		if (!fIgnoreCase) {
371
			int i= text.indexOf(p, start);
372
			if (i == -1 || i > max)
373
				return -1;
374
			return i;
375
		}
376
377
		for (int i= start; i <= max; ++i) {
378
			if (text.regionMatches(true, i, p, 0, plen))
379
				return i;
380
		}
381
382
		return -1;
383
	}
384
}
(-)src/org/eclipse/wst/sse/ui/filter/SWTUtil.java (+166 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 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
package org.eclipse.wst.sse.ui.filter;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.accessibility.AccessibleAdapter;
15
import org.eclipse.swt.accessibility.AccessibleEvent;
16
import org.eclipse.swt.dnd.DragSource;
17
import org.eclipse.swt.dnd.DropTarget;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Caret;
22
import org.eclipse.swt.widgets.Combo;
23
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.widgets.Display;
25
import org.eclipse.swt.widgets.Menu;
26
import org.eclipse.swt.widgets.ScrollBar;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.swt.widgets.Table;
29
import org.eclipse.swt.widgets.Widget;
30
31
import org.eclipse.core.runtime.Assert;
32
33
import org.eclipse.jface.dialogs.IDialogConstants;
34
import org.eclipse.jface.layout.PixelConverter;
35
import org.eclipse.jface.resource.JFaceResources;
36
37
38
/**
39
 * Utility class to simplify access to some SWT resources.
40
 */
41
public class SWTUtil {
42
43
	/**
44
	 * The default visible item count for {@link Combo}s.
45
	 * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=245569 .
46
	 *
47
	 * @see Combo#setVisibleItemCount(int)
48
	 *
49
	 * @since 3.5
50
	 */
51
	public static final int COMBO_VISIBLE_ITEM_COUNT= 30;
52
53
	/**
54
	 * Returns the standard display to be used. The method first checks, if
55
	 * the thread calling this method has an associated display. If so, this
56
	 * display is returned. Otherwise the method returns the default display.
57
	 * @return returns the standard display to be used
58
	 */
59
	public static Display getStandardDisplay() {
60
		Display display;
61
		display= Display.getCurrent();
62
		if (display == null)
63
			display= Display.getDefault();
64
		return display;
65
	}
66
67
	/**
68
	 * Returns the shell for the given widget. If the widget doesn't represent
69
	 * a SWT object that manage a shell, <code>null</code> is returned.
70
	 * @param widget the widget
71
	 *
72
	 * @return the shell for the given widget
73
	 */
74
	public static Shell getShell(Widget widget) {
75
		if (widget instanceof Control)
76
			return ((Control)widget).getShell();
77
		if (widget instanceof Caret)
78
			return ((Caret)widget).getParent().getShell();
79
		if (widget instanceof DragSource)
80
			return ((DragSource)widget).getControl().getShell();
81
		if (widget instanceof DropTarget)
82
			return ((DropTarget)widget).getControl().getShell();
83
		if (widget instanceof Menu)
84
			return ((Menu)widget).getParent().getShell();
85
		if (widget instanceof ScrollBar)
86
			return ((ScrollBar)widget).getParent().getShell();
87
88
		return null;
89
	}
90
91
92
	/**
93
	 * Returns a width hint for a button control.
94
	 * @param button the button
95
	 * @return the width hint
96
	 */
97
	public static int getButtonWidthHint(Button button) {
98
		button.setFont(JFaceResources.getDialogFont());
99
		PixelConverter converter= new PixelConverter(button);
100
		int widthHint= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
101
		return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
102
	}
103
104
	/**
105
	 * Sets width and height hint for the button control.
106
	 * <b>Note:</b> This is a NOP if the button's layout data is not
107
	 * an instance of <code>GridData</code>.
108
	 *
109
	 * @param button	the button for which to set the dimension hint
110
	 */
111
	public static void setButtonDimensionHint(Button button) {
112
		Assert.isNotNull(button);
113
		Object gd= button.getLayoutData();
114
		if (gd instanceof GridData) {
115
			((GridData)gd).widthHint= getButtonWidthHint(button);
116
			((GridData)gd).horizontalAlignment = GridData.FILL;
117
		}
118
	}
119
120
	public static int getTableHeightHint(Table table, int rows) {
121
		if (table.getFont().equals(JFaceResources.getDefaultFont()))
122
			table.setFont(JFaceResources.getDialogFont());
123
		int result= table.getItemHeight() * rows + table.getHeaderHeight();
124
		if (table.getLinesVisible())
125
			result+= table.getGridLineWidth() * (rows - 1);
126
		return result;
127
	}
128
129
	/**
130
	 * Adds an accessibility listener returning the given fixed name.
131
	 *
132
	 * @param control the control to add the accessibility support to
133
	 * @param text the name
134
	 */
135
	public static void setAccessibilityText(Control control, final String text) {
136
		control.getAccessible().addAccessibleListener(new AccessibleAdapter() {
137
			public void getName(AccessibleEvent e) {
138
				e.result= text;
139
			}
140
		});
141
	}
142
143
	/**
144
	 * Sets the default visible item count for {@link Combo}s.
145
	 * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=7845 .
146
	 *
147
	 * @param combo the combo
148
	 *
149
	 * @see Combo#setVisibleItemCount(int)
150
	 * @see #COMBO_VISIBLE_ITEM_COUNT
151
	 *
152
	 * @since 3.5
153
	 */
154
	public static void setDefaultVisibleItemCount(Combo combo) {
155
		combo.setVisibleItemCount(COMBO_VISIBLE_ITEM_COUNT);
156
	}
157
158
	public static GridLayout newLayoutNoMargins(int columns) {
159
		GridLayout layout= new GridLayout(columns, false);
160
		layout.marginWidth= 0;
161
		layout.marginHeight= 0;
162
		return layout;
163
	}
164
165
166
}
(-)src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java (+1 lines)
Lines 185-190 Link Here
185
	public static String ShowPropertiesAction_0;
185
	public static String ShowPropertiesAction_0;
186
	public static String ContentOutlineConfiguration_0;
186
	public static String ContentOutlineConfiguration_0;
187
	public static String ContentOutlineConfiguration_1;
187
	public static String ContentOutlineConfiguration_1;
188
	public static String ContentOutlineConfiguration_2;
188
	public static String AbstractOpenOn_0;
189
	public static String AbstractOpenOn_0;
189
	public static String FormatActionDelegate_jobName;
190
	public static String FormatActionDelegate_jobName;
190
	public static String FormatActionDelegate_errorStatusMessage;
191
	public static String FormatActionDelegate_errorStatusMessage;
(-)src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties (+1 lines)
Lines 159-164 Link Here
159
ShowPropertiesAction_0=P&roperties
159
ShowPropertiesAction_0=P&roperties
160
ContentOutlineConfiguration_0=Collapse All
160
ContentOutlineConfiguration_0=Collapse All
161
ContentOutlineConfiguration_1=Link with Editor
161
ContentOutlineConfiguration_1=Link with Editor
162
ContentOutlineConfiguration_2=Filters
162
AbstractOpenOn_0=Current text selection does not resolve to a file
163
AbstractOpenOn_0=Current text selection does not resolve to a file
163
FormatActionDelegate_jobName=Formatting...
164
FormatActionDelegate_jobName=Formatting...
164
FormatActionDelegate_errorStatusMessage=Exceptions occurred while formatting documents
165
FormatActionDelegate_errorStatusMessage=Exceptions occurred while formatting documents
(-)src/org/eclipse/wst/sse/ui/views/contentoutline/ContentOutlineConfiguration.java (-1 / +14 lines)
Lines 86-91 Link Here
86
	private IContributionItem[] fMenuContributions = null;
86
	private IContributionItem[] fMenuContributions = null;
87
	private IContributionItem[] fToolbarContributions = null;
87
	private IContributionItem[] fToolbarContributions = null;
88
	private final String OUTLINE_LINK_PREF = "outline-link-editor"; //$NON-NLS-1$
88
	private final String OUTLINE_LINK_PREF = "outline-link-editor"; //$NON-NLS-1$
89
	private final String OUTLINE_FILTER_PREF = "org.eclipse.wst.sse.ui.OutlinePage"; //$NON-NLS-1$
90
	
91
	private String fOutlineFilterPref = OUTLINE_FILTER_PREF; //$NON-NLS-1$
89
	ImageDescriptor SYNCED_D = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_DLCL_SYNCED);
92
	ImageDescriptor SYNCED_D = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_DLCL_SYNCED);
90
	ImageDescriptor SYNCED_E = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_ELCL_SYNCED);
93
	ImageDescriptor SYNCED_E = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_ELCL_SYNCED);
91
94
Lines 107-113 Link Here
107
	 */
110
	 */
108
	protected IContributionItem[] createMenuContributions(TreeViewer viewer) {
111
	protected IContributionItem[] createMenuContributions(TreeViewer viewer) {
109
		IContributionItem toggleLinkItem = new PropertyChangeUpdateActionContributionItem(new ToggleLinkAction(getPreferenceStore(), OUTLINE_LINK_PREF));
112
		IContributionItem toggleLinkItem = new PropertyChangeUpdateActionContributionItem(new ToggleLinkAction(getPreferenceStore(), OUTLINE_LINK_PREF));
110
		IContributionItem[] items = new IContributionItem[]{toggleLinkItem};
113
		IContributionItem filterItem = new CustomFilterActionContributionItem(new CustomFilterAction(getPreferenceStore(),fOutlineFilterPref, viewer),fOutlineFilterPref, getPreferenceStore(), viewer );
114
115
		IContributionItem[] items = new IContributionItem[]{toggleLinkItem, filterItem};
111
		return items;
116
		return items;
112
	}
117
	}
113
118
Lines 313-316 Link Here
313
			fMenuContributions = null;
318
			fMenuContributions = null;
314
		}
319
		}
315
	}
320
	}
321
	
322
	// added
323
	
324
	public void setOutlineFilterTarget(String targetId){
325
		fOutlineFilterPref = targetId;
326
	}
327
328
	
316
}
329
}
(-)src/org/eclipse/wst/sse/ui/views/contentoutline/CustomFilterAction.java (+343 lines)
Added Link Here
1
package org.eclipse.wst.sse.ui.views.contentoutline;
2
3
	/*******************************************************************************
4
	 * Copyright (c) 2001, 2010 IBM Corporation and others.
5
	 * All rights reserved. This program and the accompanying materials
6
	 * are made available under the terms of the Eclipse Public License v1.0
7
	 * which accompanies this distribution, and is available at
8
	 * http://www.eclipse.org/legal/epl-v10.html
9
	 *
10
	 * Contributors:
11
	 *     IBM Corporation - initial API and implementation
12
	 *******************************************************************************/
13
14
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.HashSet;
18
import java.util.Iterator;
19
import java.util.Map;
20
21
import org.eclipse.core.runtime.Assert;
22
import org.eclipse.jface.preference.IPreferenceStore;
23
import org.eclipse.jface.viewers.StructuredViewer;
24
import org.eclipse.jface.viewers.ViewerFilter;
25
import org.eclipse.jface.window.Window;
26
import org.eclipse.wst.sse.ui.filter.SSECustomFiltersDialog;
27
import org.eclipse.wst.sse.ui.filter.SSEFilterDescriptor;
28
import org.eclipse.wst.sse.ui.filter.SSENamePatternFilter;
29
import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
30
import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateAction;
31
32
	/**
33
	 * Action group to add the filter action to a view part's tool bar
34
	 * menu.
35
	 * <p>
36
	 * This class may be instantiated; it is not intended to be subclassed.
37
	 * </p>
38
	 *
39
	 * @since 2.0
40
	 *
41
	 * @noextend This class is not intended to be subclassed by clients.
42
	 */
43
	public class CustomFilterAction extends PropertyChangeUpdateAction {
44
45
		
46
		private static final String SEPARATOR= ",";  //$NON-NLS-1$
47
		private final String TAG_USER_DEFINED_PATTERNS_ENABLED= "userDefinedPatternsEnabled"; //$NON-NLS-1$
48
		private final String TAG_USER_DEFINED_PATTERNS= "userDefinedPatterns"; //$NON-NLS-1$
49
		
50
		
51
		private static class FilterItem {
52
			boolean enabled;
53
			boolean previouslyEnabled;
54
			SSEFilterDescriptor descriptor;
55
			String id;
56
57
			private ViewerFilter filterInstance= null;
58
59
			public FilterItem(SSEFilterDescriptor descriptor) {
60
				this.descriptor= descriptor;
61
				this.id= descriptor.getId();
62
				this.previouslyEnabled= false;
63
				this.enabled= descriptor.isEnabled();
64
			}
65
66
			public ViewerFilter getFilterInstance() {
67
				if (filterInstance == null) {
68
					filterInstance= descriptor.createViewerFilter();
69
				}
70
				return filterInstance;
71
72
			}
73
		}
74
75
76
		private final StructuredViewer fViewer;
77
		private final SSENamePatternFilter fPatternFilter;
78
79
		private boolean fUserDefinedPatternsEnabled;
80
		private String[] fUserDefinedPatterns;
81
82
		private String[] fPreviousPatterns;
83
84
		private final Map fFilterItems;
85
86
87
		
88
		private final String fTargetId;
89
		private IPreferenceStore fStore;
90
		
91
92
		/**
93
		 * Creates a new <code>CustomFilterAction</code>.
94
		 *
95
		 * @param store     the preference Store 
96
		 * @param ownerId	the id of this action group's owner
97
		 * @param viewer	the viewer to be filtered
98
		 */
99
		public CustomFilterAction(IPreferenceStore store,String ownerId, StructuredViewer viewer) {
100
			super(SSEUIMessages.ContentOutlineConfiguration_2, store, ownerId, store.getBoolean(ownerId)); //$NON-NLS-1$
101
			Assert.isNotNull(ownerId);
102
			Assert.isNotNull(viewer);
103
			fStore = store;
104
			fTargetId= ownerId;
105
			fViewer= viewer;
106
			fPatternFilter= new SSENamePatternFilter();
107
108
			fUserDefinedPatterns= new String[0];
109
			fUserDefinedPatternsEnabled= false;
110
			fPreviousPatterns= new String[0];
111
112
			fFilterItems= new HashMap();
113
			SSEFilterDescriptor[] filterDescriptors= SSEFilterDescriptor.getFilterDescriptors(fTargetId);
114
			for (int i= 0; i < filterDescriptors.length; i++) {
115
				FilterItem item= new FilterItem(filterDescriptors[i]);
116
				fFilterItems.put(item.id, item);
117
				
118
			}
119
120
			initializeWithViewDefaults();
121
122
			updateViewerFilters();
123
					
124
		}
125
		
126
		public void update() {
127
			openDialog();
128
		}
129
		
130
		
131
132
		/*
133
		 * @see org.eclipse.jface.action.IContributionItem#isDynamic()
134
		 */
135
		public boolean isDynamic() {
136
			return true;
137
		}
138
		/**
139
		 * Returns a list of currently enabled filters. The filter
140
		 * is identified by its id.
141
		 * <p>
142
		 * This method is for internal use only and should not
143
		 * be called by clients outside of JDT/UI.
144
		 * </p>
145
		 *
146
		 * @return a list of currently enabled filters
147
		 *
148
		 * @since 3.1
149
		 *
150
		 * @noreference This method is not intended to be referenced by clients.
151
		 */
152
		public String[] internalGetEnabledFilterIds() {
153
			ArrayList enabledFilterIds= new ArrayList();
154
			for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) {
155
				FilterItem item= (FilterItem) iterator.next();
156
				if (item.enabled) {
157
					enabledFilterIds.add(item.id);
158
				}
159
			}
160
			return (String[])enabledFilterIds.toArray(new String[enabledFilterIds.size()]);
161
		}
162
163
		private void setEnabledFilterIds(String[] enabledIds) {
164
			// set all to false
165
			fUserDefinedPatternsEnabled= false;
166
			for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) {
167
				FilterItem item= (FilterItem) iterator.next();
168
				item.enabled= false;
169
			}
170
			// set enabled to true
171
			for (int i= 0; i < enabledIds.length; i++) {
172
				FilterItem item= (FilterItem) fFilterItems.get(enabledIds[i]);
173
				if (item != null) {
174
					item.enabled= true;
175
				}
176
				if (fPatternFilter.getClass().getName().equals(enabledIds[i]))
177
					fUserDefinedPatternsEnabled= true;
178
			}
179
		}
180
181
		private void setUserDefinedPatterns(String[] patterns) {
182
			fUserDefinedPatterns= patterns;
183
		}
184
185
186
		private boolean areUserDefinedPatternsEnabled() {
187
			return fUserDefinedPatternsEnabled;
188
		}
189
190
		private void setUserDefinedPatternsEnabled(boolean state) {
191
			fUserDefinedPatternsEnabled= state;
192
		}
193
194
				
195
		// ---------- viewer filter handling ----------
196
197
		private boolean updateViewerFilters() {
198
			ViewerFilter[] installedFilters= fViewer.getFilters();
199
			ArrayList viewerFilters= new ArrayList(installedFilters.length);
200
			
201
			HashSet patterns= new HashSet();
202
203
			boolean hasChange= false;
204
			boolean patternChange= false;
205
206
			for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) {
207
				FilterItem item= (FilterItem) iterator.next();
208
				if (item.descriptor.isCustomFilter()) {
209
					if (item.enabled != item.previouslyEnabled) {
210
						hasChange = true;
211
					}
212
					if (item.enabled){
213
						ViewerFilter filter= item.getFilterInstance(); // only create when changed
214
						if (filter != null) {
215
							viewerFilters.add(filter);
216
						}
217
					}
218
				} else if (item.descriptor.isPatternFilter()) {
219
					if (item.enabled) {
220
						patterns.add(item.descriptor.getPattern());
221
					}
222
					patternChange |= (item.enabled != item.previouslyEnabled);
223
				}
224
				item.previouslyEnabled= item.enabled;
225
			}
226
227
			if (areUserDefinedPatternsEnabled()) {
228
				for (int i= 0; i < fUserDefinedPatterns.length; i++) {
229
					patterns.add(fUserDefinedPatterns[i]);
230
				}
231
			}
232
			if (!patternChange) { // no pattern change so far, test if the user patterns made a difference
233
				patternChange= hasChanges(patterns, fPreviousPatterns);
234
			}
235
236
			fPreviousPatterns= (String[]) patterns.toArray(new String[patterns.size()]);
237
			if (patternChange) {
238
				fPatternFilter.setPatterns(fPreviousPatterns);
239
				if (patterns.isEmpty()) {
240
					viewerFilters.remove(fPatternFilter);
241
				} else if (!viewerFilters.contains(fPatternFilter)) {
242
					boolean contains = false;
243
					for (int i=0; i< viewerFilters.size();i++){
244
						if (viewerFilters.get(i) instanceof SSENamePatternFilter){
245
							SSENamePatternFilter filter = (SSENamePatternFilter)viewerFilters.get(i);
246
							String[] a1 =filter.getPatterns();
247
							String[] a2 =fPatternFilter.getPatterns();
248
							if (a1[0].equals(a2[0]))
249
								contains= true;
250
							else {
251
								viewerFilters.remove(i);
252
							}
253
							break;
254
						}
255
					}
256
					if (!contains)
257
						viewerFilters.add(fPatternFilter);
258
				}
259
				hasChange= true;
260
			}
261
			if (hasChange) {
262
				fViewer.setFilters((ViewerFilter[]) viewerFilters.toArray(new ViewerFilter[viewerFilters.size()])); // will refresh
263
			}
264
			return hasChange;
265
		}
266
267
		private boolean hasChanges(HashSet patterns, String[] oldPatterns) {
268
			HashSet copy= (HashSet) patterns.clone();
269
			for (int i= 0; i < oldPatterns.length; i++) {
270
				boolean found= copy.remove(oldPatterns[i]);
271
				if (!found)
272
					return true;
273
			}
274
			return !copy.isEmpty();
275
		}
276
277
		// ---------- view kind/defaults persistency ----------
278
279
		private void initializeWithViewDefaults() {
280
			// get default values for view
281
			
282
			
283
			fUserDefinedPatternsEnabled= fStore.getBoolean(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED));
284
			setUserDefinedPatterns(SSECustomFiltersDialog.convertFromString(fStore.getString(getPreferenceKey(TAG_USER_DEFINED_PATTERNS)), SEPARATOR));
285
286
			for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) {
287
				FilterItem item= (FilterItem) iterator.next();
288
				String id= item.id;
289
				// set default to value from plugin contributions (fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=73991 ):
290
				fStore.setDefault(id, item.descriptor.isEnabled());
291
				item.enabled= fStore.getBoolean(id);
292
			}
293
		
294
		}
295
296
		private void storeViewDefaults() {
297
			// get default values for view
298
			
299
			fStore.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED), fUserDefinedPatternsEnabled);
300
			fStore.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS), SSECustomFiltersDialog.convertToString(fUserDefinedPatterns ,SEPARATOR));
301
302
			boolean fFilterSelected = false;
303
			for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) {
304
				FilterItem item= (FilterItem) iterator.next();
305
				fStore.setValue(item.id, item.enabled);
306
				if (item.enabled)
307
					fFilterSelected = true;
308
			}
309
310
			fStore.setValue(fTargetId, fUserDefinedPatternsEnabled || fFilterSelected);
311
			
312
		}
313
314
		private String getPreferenceKey(String tag) {
315
			return "CustomFiltersActionGroup." + fTargetId + '.' + tag; //$NON-NLS-1$
316
		}
317
318
		
319
		private void openDialog() {
320
			SSECustomFiltersDialog dialog= new SSECustomFiltersDialog(
321
				fViewer.getControl().getShell(),
322
				fTargetId,
323
				areUserDefinedPatternsEnabled(),
324
				fUserDefinedPatterns,
325
				internalGetEnabledFilterIds());
326
327
			if (dialog.open() == Window.OK) {
328
				setEnabledFilterIds(dialog.getEnabledFilterIds());
329
				setUserDefinedPatternsEnabled(dialog.areUserDefinedPatternsEnabled());
330
				setUserDefinedPatterns(dialog.getUserDefinedPatterns());
331
				storeViewDefaults();
332
333
				updateViewerFilters();
334
			}
335
			else {
336
				storeViewDefaults();
337
			}
338
		}
339
		
340
		
341
342
	}
343
(-)src/org/eclipse/wst/sse/ui/views/contentoutline/CustomFilterActionContributionItem.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2001, 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
package org.eclipse.wst.sse.ui.views.contentoutline;
13
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.ActionContributionItem;
16
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.swt.events.MenuEvent;
19
import org.eclipse.swt.events.MenuListener;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.events.SelectionListener;
22
import org.eclipse.swt.widgets.Menu;
23
import org.eclipse.swt.widgets.MenuItem;
24
import org.eclipse.ui.texteditor.IUpdate;
25
26
/**
27
 * A listener on the given action's PreferenceStore. It calls .update() on the
28
 * action when the given key changes value.
29
 */
30
public class CustomFilterActionContributionItem extends ActionContributionItem {
31
32
	
33
	
34
	private String fProperty = null;
35
	private IPreferenceStore fStore;
36
	private int fIndex;
37
38
	public CustomFilterActionContributionItem(Action action, String preference, IPreferenceStore store, Viewer viewer) {
39
		super(action);
40
		fProperty = preference;
41
		fStore = store;
42
	}
43
	
44
	/*
45
	 * Overrides method from ContributionItem.
46
	 */
47
	public void fill(Menu menu, int index) {
48
		
49
		super.fill(menu, index);
50
		fIndex = index;
51
		MenuItem filterMenuItem = menu.getItem(index);
52
		
53
		menu.addMenuListener(new MenuListener() {
54
			
55
			public void menuShown(MenuEvent e) {
56
				Object obj =e.getSource();
57
				if (obj instanceof Menu){
58
					Menu menu = (Menu)obj;
59
					menu.getItem(fIndex).setSelection(fStore.getBoolean(fProperty));
60
				}
61
			}
62
			
63
			public void menuHidden(MenuEvent e) {
64
				
65
			}
66
		});
67
	
68
		filterMenuItem.addSelectionListener(new SelectionListener() {
69
			
70
			public void widgetSelected(SelectionEvent e) {
71
				((IUpdate) getAction()).update();
72
				
73
			}
74
			
75
			public void widgetDefaultSelected(SelectionEvent e) {
76
				
77
			}
78
		});
79
		
80
	}
81
82
	
83
}
(-)plugin.properties (-1 / +11 lines)
Lines 137-140 Link Here
137
# Menu contributions
137
# Menu contributions
138
command.toggle.comment.mnemonic=T
138
command.toggle.comment.mnemonic=T
139
command.add.block.comment.mnemonic=A
139
command.add.block.comment.mnemonic=A
140
command.remove.block.comment.mnemonic=R
140
command.remove.block.comment.mnemonic=R
141
142
143
HideComments.label=Comments
144
HideComments.description=Hides Comments
145
146
HideProcessingInstruction.label=Processing Instructions
147
HideProcessingInstruction.description=Hides Processing Instructions
148
149
HideCDATASection.label=CDATA
150
HideCDATASection.description=Hides CDATA Section Tags
(-)plugin.xml (+29 lines)
Lines 1661-1665 Link Here
1661
       </contentTypeIdentifier>
1661
       </contentTypeIdentifier>
1662
    </inserter>
1662
    </inserter>
1663
 </extension>
1663
 </extension>
1664
 <extension
1665
       point="org.eclipse.wst.sse.ui.sseElementFilter">
1666
       <filter
1667
            targetId="org.eclipse.wst.xml.ui.OutlinePage"
1668
            name="%HideComments.label"
1669
            enabled="false"
1670
            description="%HideComments.description"
1671
            class="org.eclipse.wst.xml.ui.internal.contentoutline.XMLCommentFilter"
1672
            id="org.eclipse.wst.xml.ui.internal.contentoutline.XMLCommentFilter">
1673
      </filter>
1674
      <filter
1675
            targetId="org.eclipse.wst.xml.ui.OutlinePage"
1676
            name="%HideProcessingInstruction.label"
1677
            enabled="false"
1678
            description="%HideProcessingInstruction.description"
1679
            class="org.eclipse.wst.xml.ui.internal.contentoutline.XMLProcessingInstructionFilter"
1680
            id="org.eclipse.wst.xml.ui.internal.contentoutline.XMLProcessingInstructionFilter">
1681
      </filter>
1682
      <filter
1683
            targetId="org.eclipse.wst.xml.ui.OutlinePage"
1684
            name="%HideCDATASection.label"
1685
            enabled="false"
1686
            description="%HideCDATASection.description"
1687
            class="org.eclipse.wst.xml.ui.internal.contentoutline.XMLCDATASectionFilter"
1688
            id="org.eclipse.wst.xml.ui.internal.contentoutline.XMLCDATASectionFilter">
1689
      </filter>
1690
 </extension>
1691
 
1692
 
1664
1693
1665
</plugin>
1694
</plugin>
(-)src/org/eclipse/wst/xml/ui/internal/contentoutline/XMLCDATASectionFilter.java (+16 lines)
Added Link Here
1
package org.eclipse.wst.xml.ui.internal.contentoutline;
2
3
import org.eclipse.jface.viewers.Viewer;
4
import org.eclipse.jface.viewers.ViewerFilter;
5
import org.eclipse.wst.xml.core.internal.document.CDATASectionImpl;
6
7
public class XMLCDATASectionFilter extends ViewerFilter {
8
9
	public boolean select(Viewer viewer, Object parent, Object element) {
10
		if (element instanceof CDATASectionImpl){
11
			return false;
12
		}
13
		return true;
14
	}
15
16
}
(-)src/org/eclipse/wst/xml/ui/internal/contentoutline/XMLCommentFilter.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 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
package org.eclipse.wst.xml.ui.internal.contentoutline;
12
13
14
import org.eclipse.jface.viewers.Viewer;
15
import org.eclipse.jface.viewers.ViewerFilter;
16
import org.eclipse.wst.xml.core.internal.document.CommentImpl;
17
18
19
/**
20
 * Filters package declarations
21
 */
22
public class XMLCommentFilter extends ViewerFilter {
23
24
	/*
25
	 * @see ViewerFilter
26
	 */
27
	public boolean select(Viewer viewer, Object parent, Object element) {
28
		if (element instanceof CommentImpl){
29
			return false;
30
		}
31
		return true;
32
	}
33
}
(-)src/org/eclipse/wst/xml/ui/internal/contentoutline/XMLProcessingInstructionFilter.java (+16 lines)
Added Link Here
1
package org.eclipse.wst.xml.ui.internal.contentoutline;
2
3
import org.eclipse.jface.viewers.Viewer;
4
import org.eclipse.jface.viewers.ViewerFilter;
5
import org.eclipse.wst.xml.core.internal.document.ProcessingInstructionImpl;
6
7
public class XMLProcessingInstructionFilter extends ViewerFilter {
8
9
	public boolean select(Viewer viewer, Object parent, Object element) {
10
		if (element instanceof ProcessingInstructionImpl){
11
			return false;
12
		}
13
		return true;
14
	}
15
16
}
(-)src/org/eclipse/wst/xml/ui/views/contentoutline/XMLContentOutlineConfiguration.java (+2 lines)
Lines 266-271 Link Here
266
	 * Preference key for Show Attributes
266
	 * Preference key for Show Attributes
267
	 */
267
	 */
268
	private final String OUTLINE_SHOW_ATTRIBUTE_PREF = "outline-show-attribute"; //$NON-NLS-1$
268
	private final String OUTLINE_SHOW_ATTRIBUTE_PREF = "outline-show-attribute"; //$NON-NLS-1$
269
	private final String OUTLINE_FILTER_PREF = "org.eclipse.wst.xml.ui.OutlinePage"; //$NON-NLS-1$
269
270
270
	/**
271
	/**
271
	 * Create new instance of XMLContentOutlineConfiguration
272
	 * Create new instance of XMLContentOutlineConfiguration
Lines 304-309 Link Here
304
			store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.NOTATION_NODE, "11, true");
305
			store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.NOTATION_NODE, "11, true");
305
		if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.TEXT_NODE).length() == 0)
306
		if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.TEXT_NODE).length() == 0)
306
			store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.TEXT_NODE, "12, false");
307
			store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.TEXT_NODE, "12, false");
308
		super.setOutlineFilterTarget(OUTLINE_FILTER_PREF);
307
	}
309
	}
308
310
309
	/*
311
	/*

Return to bug 109045