1 11 package org.eclipse.ltk.internal.ui.refactoring.actions; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.team.core.diff.IThreeWayDiff; 17 import org.eclipse.team.core.mapping.IMergeContext; 18 import org.eclipse.team.core.mapping.ISynchronizationContext; 19 20 import org.eclipse.core.runtime.Assert; 21 22 import org.eclipse.core.resources.IProject; 23 import org.eclipse.core.resources.ResourcesPlugin; 24 25 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 26 27 import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryImplementation; 28 import org.eclipse.ltk.internal.ui.refactoring.IRefactoringHelpContextIds; 29 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages; 30 import org.eclipse.ltk.internal.ui.refactoring.model.ModelMessages; 31 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorSynchronizationProxy; 32 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringHistoryMergeWizard; 33 34 import org.eclipse.swt.widgets.Shell; 35 36 import org.eclipse.jface.action.Action; 37 import org.eclipse.jface.window.Window; 38 import org.eclipse.jface.wizard.WizardDialog; 39 40 import org.eclipse.ui.PlatformUI; 41 42 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration; 43 44 49 public final class AcceptRefactoringsAction extends Action { 50 51 52 private static final class RefactoringHistoryAcceptConfiguration extends RefactoringHistoryControlConfiguration { 53 54 60 public RefactoringHistoryAcceptConfiguration(final IProject project) { 61 super(project, false, false); 62 } 63 64 67 public String getProjectPattern() { 68 return ModelMessages.AcceptRefactoringsAction_wizard_project_pattern; 69 } 70 71 74 public String getWorkspaceCaption() { 75 return ModelMessages.AcceptRefactoringsAction_wizard_workspace_caption; 76 } 77 } 78 79 80 private static final class RefactoringHistoryAcceptWizard extends RefactoringHistoryMergeWizard { 81 82 85 public RefactoringHistoryAcceptWizard() { 86 super(RefactoringUIMessages.RefactoringWizard_refactoring, ModelMessages.AcceptRefactoringsAction_wizard_title, ModelMessages.AcceptRefactoringsAction_wizard_description); 87 } 88 } 89 90 91 private static final int SIZING_WIZARD_HEIGHT= 520; 92 93 94 private static final int SIZING_WIZARD_WIDTH= 470; 95 96 97 private final ISynchronizationContext fContext; 98 99 100 private RefactoringDescriptorProxy[] fProxies= null; 101 102 103 private final Shell fShell; 104 105 113 public AcceptRefactoringsAction(final ISynchronizationContext context, final Shell shell) { 114 Assert.isNotNull(context); 115 Assert.isNotNull(shell); 116 fContext= context; 117 fShell= shell; 118 setText(ModelMessages.AcceptRefactoringsAction_title); 119 setToolTipText(ModelMessages.AcceptRefactoringsAction_tool_tip); 120 setDescription(ModelMessages.AcceptRefactoringsAction_description); 121 } 122 123 126 public boolean isEnabled() { 127 if (fProxies != null && fProxies.length > 0) { 128 for (int index= 0; index < fProxies.length; index++) { 129 if (fProxies[index] instanceof RefactoringDescriptorSynchronizationProxy) { 130 final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) fProxies[index]; 131 if (proxy.getDirection() == IThreeWayDiff.INCOMING) 132 return true; 133 } 134 } 135 } 136 return false; 137 } 138 139 142 public void run() { 143 if (fProxies != null && fProxies.length > 0) { 144 final RefactoringHistoryMergeWizard wizard= new RefactoringHistoryAcceptWizard(); 145 int result= Window.OK; 146 try { 147 final WizardDialog dialog= new WizardDialog(fShell, wizard); 148 IProject project= null; 149 Set proxies= new HashSet (); 150 for (int index= 0; index < fProxies.length; index++) { 151 if (fProxies[index] instanceof RefactoringDescriptorSynchronizationProxy) { 152 final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) fProxies[index]; 153 if (proxy.getDirection() == IThreeWayDiff.INCOMING) 154 proxies.add(proxy); 155 } 156 String name= fProxies[index].getProject(); 157 if (name != null && !"".equals(name)) project= ResourcesPlugin.getWorkspace().getRoot().getProject(name); 159 } 160 wizard.setConfiguration(new RefactoringHistoryAcceptConfiguration(project)); 161 wizard.setInput(new RefactoringHistoryImplementation((RefactoringDescriptorProxy[]) proxies.toArray(new RefactoringDescriptorProxy[proxies.size()]))); 162 dialog.create(); 163 dialog.getShell().setSize(Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), SIZING_WIZARD_HEIGHT); 164 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IRefactoringHelpContextIds.REFACTORING_ACCEPT_REFACTORING_PAGE); 165 result= dialog.open(); 166 } finally { 167 if (result != Window.CANCEL && fContext instanceof IMergeContext) { 168 final IMergeContext context= (IMergeContext) fContext; 169 wizard.resolveConflicts(context); 170 } 171 } 172 } 173 } 174 175 181 public void setRefactoringDescriptors(final RefactoringDescriptorProxy[] proxies) { 182 Assert.isNotNull(proxies); 183 fProxies= proxies; 184 } 185 } | Popular Tags |