Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: a437d6cdabfaa5249d327cb20caf0a523a63a352 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
 * Copyright (c) 2001, 2006 IBM Corporation and others.
 * 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
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation 
 *     Trung de Irene <trungha@ca.ibm.com>
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.dialogs;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification;
import org.eclipse.wst.xsd.ui.internal.editor.Messages;
import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;

/**
 * The BuiltInTypesFilteringDialog is a SelectionDialog that allows the user to
 *  select a ...
 */
public class SelectBuiltInTypesForFilteringDialog extends CheckedTreeSelectionDialog {

	public final static String CUSTOM_LIST_SEPARATOR = XSDEditorPlugin.CUSTOM_LIST_SEPARATOR;

	public SelectBuiltInTypesForFilteringDialog(Shell parent, 
			ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
		super(parent, labelProvider, contentProvider);

		init();
	}
	
	public CheckboxTreeViewer getTreeViewer(){
		return super.getTreeViewer();
	}
	
	private void init(){
		// grey state enable
		setContainerMode(true);
		
		setTitle(Messages._UI_LABEL_SET_COMMON_BUILT_IN_TYPES);
		setMessage(Messages._UI_LABEL_SELECT_TYPES_FILTER_OUT);
		
		//super.create();
		//super.getTreeViewer().setSorter(new ViewerSorter());
		
	}
	
	/**
	 *   Returns a String acting as list of built-in types selected by the user
	 * in the filter dialog (white space acts as the item separator).
	 *   Suggest using getSelectedBuiltInTypesFromString
	 * to get a concrete array of selected types.
	 *   We can only store String in the plugin preference's storage so we have 
	 * use this method for conversion
	 */
	public static String getTypesListInString(Object[] chosenTypes) {
		String returningList = ""; //$NON-NLS-1$
		for (int i = 0; i < chosenTypes.length; i++){
			if ( chosenTypes[i] instanceof ComponentSpecification){
				ComponentSpecification aType = 
					(ComponentSpecification) chosenTypes[i];

				returningList += aType.getName() + CUSTOM_LIST_SEPARATOR;
			}
			/* else selectedBuiltInTypes[i] instanceof List, ie. a parentNode
			 * we ignore it. */
		}
		return returningList;
	}
	
	/**
	 * Filters out all built-In type not recorded in the 'listString' and 
	 * returns the result in a List
	 * Warning: recursive method
	 * @param listString 
	 * @param aContainer 
	 * 			Containing all types
	 * @return a subset of what 'aContainer' has as specified by 'listString'
	 */
	public static List getSelectedBuiltInTypesFromString(String listString, 
			List aContainer) {
		List selectedTypes = new ArrayList();

		// ignore the 'header' item in the container, starting from i = 1
		for (int i = 1; i < aContainer.size(); i++){
			Object o = aContainer.get(i);
			if ( o instanceof ComponentSpecification){
				ComponentSpecification aType = (ComponentSpecification) o;
				String typeName = aType.getName();
				// if typeName's name appears in 'listString'
				if ( listString.indexOf(typeName + CUSTOM_LIST_SEPARATOR) != -1)
					selectedTypes.add(o);
			}
			else if ( o instanceof List){
				selectedTypes.addAll( getSelectedBuiltInTypesFromString(listString, (List) o) ); 
			}
		}
		return selectedTypes;
	}
}

Back to the top