]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2005, 2011 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.jdt.internal.ui.wizards.buildpaths.newsourcepage; | |
12 | ||
13 | import java.util.List; | |
14 | ||
15 | import org.eclipse.swt.SWT; | |
16 | import org.eclipse.swt.events.SelectionAdapter; | |
17 | import org.eclipse.swt.events.SelectionEvent; | |
18 | import org.eclipse.swt.events.SelectionListener; | |
19 | import org.eclipse.swt.layout.GridLayout; | |
20 | import org.eclipse.swt.widgets.Button; | |
21 | import org.eclipse.swt.widgets.Composite; | |
22 | import org.eclipse.swt.widgets.Control; | |
23 | import org.eclipse.swt.widgets.Shell; | |
24 | ||
25 | import org.eclipse.core.runtime.Assert; | |
26 | ||
27 | import org.eclipse.core.resources.IFolder; | |
28 | ||
29 | import org.eclipse.jface.dialogs.IDialogConstants; | |
30 | import org.eclipse.jface.dialogs.MessageDialog; | |
31 | import org.eclipse.jface.window.Window; | |
32 | ||
33 | import org.eclipse.jdt.internal.corext.util.Messages; | |
34 | ||
35 | import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels; | |
36 | import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; | |
37 | import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.IRemoveLinkedFolderQuery; | |
38 | ||
39 | /** | |
40 | * Dialog to prompt whether a linked folder should be deleted. | |
41 | * | |
42 | */ | |
43 | class RemoveLinkedFolderDialog extends MessageDialog { | |
44 | ||
45 | /** The remove status */ | |
46 | private int fRemoveStatus= IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH_AND_FOLDER; | |
47 | ||
48 | /** The remove build path and folder button */ | |
49 | private Button fRemoveBuildPathAndFolder; | |
50 | ||
51 | /** The remove build path button */ | |
52 | private Button fRemoveBuildPath; | |
53 | ||
54 | /** | |
55 | * Creates a new remove linked folder dialog. | |
56 | * | |
57 | * @param shell the parent shell to use | |
58 | * @param folder the linked folder to remove | |
59 | */ | |
60 | RemoveLinkedFolderDialog(final Shell shell, final IFolder folder) { | |
61 | super(shell, NewWizardMessages.ClasspathModifierQueries_confirm_remove_linked_folder_label, null, Messages.format(NewWizardMessages.ClasspathModifierQueries_confirm_remove_linked_folder_message, new Object[] { BasicElementLabels.getPathLabel(folder.getFullPath(), false)}), MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, 0); // yes is the default | |
62 | Assert.isTrue(folder.isLinked()); | |
63 | } | |
64 | ||
65 | @Override | |
66 | protected Control createCustomArea(final Composite parent) { | |
67 | ||
68 | final Composite composite= new Composite(parent, SWT.NONE); | |
69 | composite.setLayout(new GridLayout()); | |
70 | ||
71 | fRemoveBuildPathAndFolder= new Button(composite, SWT.RADIO); | |
72 | fRemoveBuildPathAndFolder.addSelectionListener(selectionListener); | |
73 | ||
74 | fRemoveBuildPathAndFolder.setText(NewWizardMessages.ClasspathModifierQueries_delete_linked_folder); | |
75 | fRemoveBuildPathAndFolder.setFont(parent.getFont()); | |
76 | ||
77 | fRemoveBuildPath= new Button(composite, SWT.RADIO); | |
78 | fRemoveBuildPath.addSelectionListener(selectionListener); | |
79 | ||
80 | fRemoveBuildPath.setText(NewWizardMessages.ClasspathModifierQueries_do_not_delete_linked_folder); | |
81 | fRemoveBuildPath.setFont(parent.getFont()); | |
82 | ||
83 | fRemoveBuildPathAndFolder.setSelection(fRemoveStatus == IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH_AND_FOLDER); | |
84 | fRemoveBuildPath.setSelection(fRemoveStatus == IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH); | |
85 | ||
86 | return composite; | |
87 | } | |
88 | ||
89 | private SelectionListener selectionListener= new SelectionAdapter() { | |
90 | ||
91 | @Override | |
92 | public final void widgetSelected(final SelectionEvent event) { | |
93 | final Button button= (Button) event.widget; | |
94 | if (button.getSelection()) | |
95 | fRemoveStatus= (button == fRemoveBuildPathAndFolder) ? IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH_AND_FOLDER : IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH; | |
96 | } | |
97 | }; | |
98 | ||
99 | /** | |
100 | * Returns the remove status. | |
101 | * | |
102 | * @return the remove status, one of IRemoveLinkedFolderQuery#REMOVE_XXX | |
103 | */ | |
104 | public final int getRemoveStatus() { | |
105 | return fRemoveStatus; | |
106 | } | |
107 | ||
108 | public void generated_8346978573632471346(final List<Object> elementsToRemove, final List<IFolder> foldersToDelete, Object element, IFolder folder) { | |
109 | final int result= open() == Window.OK?getRemoveStatus():IRemoveLinkedFolderQuery.REMOVE_CANCEL; | |
110 | ||
111 | if (result != IRemoveLinkedFolderQuery.REMOVE_CANCEL) { | |
112 | if (result == IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH) { | |
113 | elementsToRemove.add(element); | |
114 | } else if (result == IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH_AND_FOLDER) { | |
115 | elementsToRemove.add(element); | |
116 | foldersToDelete.add(folder); | |
117 | } | |
118 | } | |
119 | } | |
120 | } |