1 11 package org.eclipse.team.internal.ccvs.ui.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 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 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, getMessage(projects), 51 MessageDialog.QUESTION, 52 new String [] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, 53 0); } 55 56 static String 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 getMessage(IProject[] projects) { 64 if (projects.length == 1) { 65 IProject project = projects[0]; 66 return NLS.bind(CVSUIMessages.Unmanage_message, new String [] { project.getName() }); 67 } 68 else { 69 return NLS.bind(CVSUIMessages.Unmanage_messageN, new String [] { new Integer (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 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 114 public void execute(IAction action) throws InterruptedException , InvocationTargetException { 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 () { 126 public void run() { 127 result[0] = dialog.open(); 128 } 129 }); 130 deleteContent = dialog.getDeleteContent(); 131 return result[0] == 0; } 133 134 137 protected String getErrorTitle() { 138 return CVSUIMessages.Unmanage_unmanagingError; 139 } 140 141 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 |