Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4e1454f7a9529c5e59e37d234901855485a2777c (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*******************************************************************************
 * Copyright (c) 2003, 2007 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.sourcelookup.browsers;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIMessages;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.views.navigator.ResourceComparator;

/**
 * The dialog for selecting the folder for which a source container will be created.
 *
 * @since 3.0
 */
public class FolderSourceContainerDialog extends ElementTreeSelectionDialog {

	/**
	 * Constant to persist the state of the search subfolders button
	 *
	 * @since 3.2
	 */
	private static final String LAST_SUBDIR_SETTING = "EXT_FOLDER_SOURCE_LAST_SUBDIR_SETTING"; //$NON-NLS-1$

	/**
	 * Lets us control searching subfolders
	 *
	 * @since 3.2
	 */
	private Button fSubfoldersButton;

	/**
	 * stored value whether to search subfolders or not
	 *
	 * @since 3.2
	 */
	private boolean fSearchSubfolders = false;

	/**
	 * We need to add in the new control for indicating whether to search sub folders or not
	 *
	 * @since 3.2
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite parentc = (Composite)super.createDialogArea(parent);
		fSubfoldersButton = new Button(parentc, SWT.CHECK);
        fSubfoldersButton.setText(SourceLookupUIMessages.DirectorySourceContainerDialog_6);
        fSubfoldersButton.setSelection(fSearchSubfolders);
		return parentc;
	}

	/**
	 * Sets the dialog values for its construction
	 * @param parent the parent of the dialog
	 * @param labelProvider the label provider for the content of the tree in the dialog
	 * @param contentProvider the provider of the tree content for the dialog
	 */
	public FolderSourceContainerDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
		super(parent, labelProvider, contentProvider);
		setTitle(SourceLookupUIMessages.folderSelection_title);	//
		setInput(ResourcesPlugin.getWorkspace().getRoot());
        setComparator(new ResourceComparator(ResourceComparator.NAME));
		ISelectionStatusValidator validator= new ISelectionStatusValidator() {
			@Override
			public IStatus validate(Object[] selection) {
				for (int i= 0; i < selection.length; i++) {
					if (!(selection[i] instanceof IFolder)) {
						return new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), -1, SourceLookupUIMessages.sourceSearch_folderSelectionError, null); //
					}
				}
				return new Status(IStatus.OK, DebugUIPlugin.getUniqueIdentifier(), 0, IInternalDebugCoreConstants.EMPTY_STRING, null);
			}
		};
		setValidator(validator);
		setDoubleClickSelects(true);
		setAllowMultiple(true);
		setMessage(SourceLookupUIMessages.folderSelection_label);
		PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,  IDebugHelpContextIds.ADD_FOLDER_CONTAINER_DIALOG);
		setSearchSubfolders(DebugUIPlugin.getDefault().getDialogSettings().getBoolean(LAST_SUBDIR_SETTING));
		addFilter(new ViewerFilter() {
			@Override
			public boolean select(Viewer viewer, Object parentElement, Object element) {
				if(!(element instanceof IFolder)) {
					if(element instanceof IProject) {
						return ((IProject)element).isAccessible();
					}
					return false;
				}
				return true;
			}
		});
	}

	/**
	 * Returns whether the 'search subfolders' option is selected.
	 *
	 * @since 3.2
	 * @return true if the search subfolders button is selected, false otherwise.
	 */
	public boolean isSearchSubfolders() {
		return fSearchSubfolders;
	}

	/**
	 * Sets whether the 'search subfolders' option is selected.
	 *
	 * @param subfolders
	 * @since 3.2
	 */
	public void setSearchSubfolders(boolean subfolders) {
		fSearchSubfolders = subfolders;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.dialogs.SelectionStatusDialog#okPressed()
	 */
	@Override
	protected void okPressed() {
		fSearchSubfolders = fSubfoldersButton.getSelection();
		DebugUIPlugin.getDefault().getDialogSettings().put(LAST_SUBDIR_SETTING, fSearchSubfolders);
		super.okPressed();
	}

}

Back to the top