001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage;
011:
012: import org.eclipse.core.runtime.Assert;
013:
014: import org.eclipse.core.resources.IFolder;
015:
016: import org.eclipse.swt.SWT;
017: import org.eclipse.swt.events.SelectionAdapter;
018: import org.eclipse.swt.events.SelectionEvent;
019: import org.eclipse.swt.events.SelectionListener;
020: import org.eclipse.swt.layout.GridLayout;
021: import org.eclipse.swt.widgets.Button;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.swt.widgets.Control;
024: import org.eclipse.swt.widgets.Shell;
025:
026: import org.eclipse.jface.dialogs.IDialogConstants;
027: import org.eclipse.jface.dialogs.MessageDialog;
028:
029: import org.eclipse.jdt.internal.corext.util.Messages;
030:
031: import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
032: import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.IRemoveLinkedFolderQuery;
033:
034: /**
035: * Dialog to prompt whether a linked folder should be deleted.
036: *
037: */
038: class RemoveLinkedFolderDialog extends MessageDialog {
039:
040: /** The remove status */
041: private int fRemoveStatus = IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH_AND_FOLDER;
042:
043: /** The remove build path and folder button */
044: private Button fRemoveBuildPathAndFolder;
045:
046: /** The remove build path button */
047: private Button fRemoveBuildPath;
048:
049: /**
050: * Creates a new remove linked folder dialog.
051: *
052: * @param shell the parent shell to use
053: * @param folder the linked folder to remove
054: */
055: RemoveLinkedFolderDialog(final Shell shell, final IFolder folder) {
056: super (
057: shell,
058: NewWizardMessages.ClasspathModifierQueries_confirm_remove_linked_folder_label,
059: null,
060: Messages
061: .format(
062: NewWizardMessages.ClasspathModifierQueries_confirm_remove_linked_folder_message,
063: new Object[] { folder.getFullPath() }),
064: MessageDialog.QUESTION, new String[] {
065: IDialogConstants.YES_LABEL,
066: IDialogConstants.NO_LABEL }, 0); // yes is the default
067: Assert.isTrue(folder.isLinked());
068: }
069:
070: protected Control createCustomArea(final Composite parent) {
071:
072: final Composite composite = new Composite(parent, SWT.NONE);
073: composite.setLayout(new GridLayout());
074:
075: fRemoveBuildPathAndFolder = new Button(composite, SWT.RADIO);
076: fRemoveBuildPathAndFolder
077: .addSelectionListener(selectionListener);
078:
079: fRemoveBuildPathAndFolder
080: .setText(NewWizardMessages.ClasspathModifierQueries_delete_linked_folder);
081: fRemoveBuildPathAndFolder.setFont(parent.getFont());
082:
083: fRemoveBuildPath = new Button(composite, SWT.RADIO);
084: fRemoveBuildPath.addSelectionListener(selectionListener);
085:
086: fRemoveBuildPath
087: .setText(NewWizardMessages.ClasspathModifierQueries_do_not_delete_linked_folder);
088: fRemoveBuildPath.setFont(parent.getFont());
089:
090: fRemoveBuildPathAndFolder
091: .setSelection(fRemoveStatus == IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH_AND_FOLDER);
092: fRemoveBuildPath
093: .setSelection(fRemoveStatus == IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH);
094:
095: return composite;
096: }
097:
098: private SelectionListener selectionListener = new SelectionAdapter() {
099:
100: public final void widgetSelected(final SelectionEvent event) {
101: final Button button = (Button) event.widget;
102: if (button.getSelection())
103: fRemoveStatus = (button == fRemoveBuildPathAndFolder) ? IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH_AND_FOLDER
104: : IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH;
105: }
106: };
107:
108: /**
109: * Returns the remove status.
110: *
111: * @return the remove status, one of IRemoveLinkedFolderQuery#REMOVE_XXX
112: */
113: public final int getRemoveStatus() {
114: return fRemoveStatus;
115: }
116: }
|