KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > actions > UnmanageAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.team.internal.ccvs.ui.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.dialogs.IDialogConstants;
19 import org.eclipse.jface.dialogs.MessageDialog;
20 import org.eclipse.jface.window.Window;
21 import org.eclipse.osgi.util.NLS;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.*;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.*;
26 import org.eclipse.team.internal.ccvs.core.CVSException;
27 import org.eclipse.team.internal.ccvs.core.ICVSResource;
28 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
29 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
30 import org.eclipse.team.internal.ccvs.ui.operations.DisconnectOperation;
31 import org.eclipse.ui.PlatformUI;
32
33 /**
34  * Unmanage action removes the cvs feature from a project and optionally
35  * deletes the CVS meta information that is stored on disk.
36  */

37 public class UnmanageAction extends WorkspaceAction {
38     
39     static class DeleteProjectDialog extends MessageDialog {
40
41         boolean deleteContent = false;
42         Button radio1;
43         Button radio2;
44         
45         DeleteProjectDialog(Shell parentShell, IProject[] projects) {
46             super(
47                 parentShell,
48                 getTitle(projects),
49                 null, // accept the default window icon
50
getMessage(projects),
51                 MessageDialog.QUESTION,
52                 new String JavaDoc[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL},
53                 0); // yes is the default
54
}
55         
56         static String JavaDoc getTitle(IProject[] projects) {
57             if (projects.length == 1)
58                 return CVSUIMessages.Unmanage_title;
59             else
60                 return CVSUIMessages.Unmanage_titleN;
61         }
62         
63         static String JavaDoc getMessage(IProject[] projects) {
64             if (projects.length == 1) {
65                 IProject project = projects[0];
66                 return NLS.bind(CVSUIMessages.Unmanage_message, new String JavaDoc[] { project.getName() });
67             }
68             else {
69                 return NLS.bind(CVSUIMessages.Unmanage_messageN, new String JavaDoc[] { new Integer JavaDoc(projects.length).toString() });
70             }
71         }
72         
73         protected Control createCustomArea(Composite parent) {
74             Composite composite = new Composite(parent, SWT.NONE);
75             composite.setLayout(new GridLayout());
76             radio1 = new Button(composite, SWT.RADIO);
77             radio1.addSelectionListener(selectionListener);
78             
79             radio1.setText(CVSUIMessages.Unmanage_option2);
80
81             radio2 = new Button(composite, SWT.RADIO);
82             radio2.addSelectionListener(selectionListener);
83
84             radio2.setText(CVSUIMessages.Unmanage_option1);
85             
86             // set initial state
87
radio1.setSelection(deleteContent);
88             radio2.setSelection(!deleteContent);
89             
90             PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.DISCONNECT_ACTION);
91             
92             return composite;
93         }
94         
95         private SelectionListener selectionListener = new SelectionAdapter() {
96             public void widgetSelected(SelectionEvent e) {
97                 Button button = (Button) e.widget;
98                 if (button.getSelection()) {
99                     deleteContent = (button == radio1);
100                 }
101             }
102         };
103         
104         public boolean getDeleteContent() {
105             return deleteContent;
106         }
107     }
108     
109     private boolean deleteContent = false;
110     
111     /*
112      * @see IActionDelegate#run(IAction)
113      */

114     public void execute(IAction action) throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
115         if(confirmDeleteProjects()) {
116             new DisconnectOperation(getTargetPart(), getSelectedProjects(), deleteContent)
117                 .run();
118         }
119     }
120
121     boolean confirmDeleteProjects() {
122         final int[] result = new int[] { Window.OK };
123         IProject[] projects = getSelectedProjects();
124         final DeleteProjectDialog dialog = new DeleteProjectDialog(getShell(), projects);
125         getShell().getDisplay().syncExec(new Runnable JavaDoc() {
126             public void run() {
127                 result[0] = dialog.open();
128             }
129         });
130         deleteContent = dialog.getDeleteContent();
131         return result[0] == 0; // YES
132
}
133     
134     /**
135      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
136      */

137     protected String JavaDoc getErrorTitle() {
138         return CVSUIMessages.Unmanage_unmanagingError;
139     }
140
141     /**
142      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForCVSResource(org.eclipse.team.internal.ccvs.core.ICVSResource)
143      */

144     protected boolean isEnabledForCVSResource(ICVSResource cvsResource) throws CVSException {
145         IResource resource = cvsResource.getIResource();
146         return resource != null && resource.getType() == IResource.PROJECT;
147     }
148
149 }
150
Popular Tags