1 11 package org.eclipse.ui.actions; 12 13 import org.eclipse.jface.dialogs.IDialogSettings; 14 import org.eclipse.jface.viewers.ISelection; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.jface.viewers.StructuredSelection; 17 import org.eclipse.jface.wizard.WizardDialog; 18 import org.eclipse.swt.widgets.Shell; 19 import org.eclipse.ui.ISelectionListener; 20 import org.eclipse.ui.IWorkbench; 21 import org.eclipse.ui.IWorkbenchPart; 22 import org.eclipse.ui.IWorkbenchWindow; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.internal.IWorkbenchGraphicConstants; 25 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 26 import org.eclipse.ui.internal.PerspectiveTracker; 27 import org.eclipse.ui.internal.WorkbenchImages; 28 import org.eclipse.ui.internal.WorkbenchMessages; 29 import org.eclipse.ui.internal.WorkbenchPlugin; 30 import org.eclipse.ui.internal.dialogs.ImportExportWizard; 31 32 53 public class ExportResourcesAction extends BaseSelectionListenerAction 54 implements ActionFactory.IWorkbenchAction { 55 56 private static final int SIZING_WIZARD_WIDTH = 470; 57 58 private static final int SIZING_WIZARD_HEIGHT = 550; 59 60 64 private IWorkbenchWindow workbenchWindow; 65 66 70 private PerspectiveTracker tracker; 71 72 76 private final ISelectionListener selectionListener = new ISelectionListener() { 77 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 78 if (selection instanceof IStructuredSelection) { 79 IStructuredSelection structured = (IStructuredSelection) selection; 80 ExportResourcesAction.this.selectionChanged(structured); 81 } 82 } 83 }; 84 85 90 public ExportResourcesAction(IWorkbenchWindow window) { 91 this(window, WorkbenchMessages.ExportResourcesAction_text); 92 } 93 94 100 public ExportResourcesAction(IWorkbenchWindow window, String label) { 101 super(label); 102 if (window == null) { 103 throw new IllegalArgumentException (); 104 } 105 this.workbenchWindow = window; 106 tracker = new PerspectiveTracker(window, this); 107 setToolTipText(WorkbenchMessages.ExportResourcesAction_toolTip); 108 setId("export"); window.getWorkbench().getHelpSystem().setHelp(this, 110 IWorkbenchHelpContextIds.EXPORT_ACTION); 111 workbenchWindow.getSelectionService().addSelectionListener( 113 selectionListener); 114 115 setText(WorkbenchMessages.ExportResourcesAction_fileMenuText); 116 setImageDescriptor(WorkbenchImages 117 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_EXPORT_WIZ)); 118 } 119 120 126 public ExportResourcesAction(IWorkbench workbench) { 127 this(workbench.getActiveWorkbenchWindow()); 128 } 129 130 137 public ExportResourcesAction(IWorkbench workbench, String label) { 138 this(workbench.getActiveWorkbenchWindow(), label); 139 } 140 141 144 public void run() { 145 if (workbenchWindow == null) { 146 return; 148 } 149 ImportExportWizard wizard = new ImportExportWizard(ImportExportWizard.EXPORT); 150 IStructuredSelection selectionToPass; 151 ISelection workbenchSelection = workbenchWindow.getSelectionService() 153 .getSelection(); 154 if (workbenchSelection instanceof IStructuredSelection) { 155 selectionToPass = (IStructuredSelection) workbenchSelection; 156 } else { 157 selectionToPass = StructuredSelection.EMPTY; 158 } 159 160 wizard.init(workbenchWindow.getWorkbench(), selectionToPass); 161 IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault() 162 .getDialogSettings(); 163 IDialogSettings wizardSettings = workbenchSettings 164 .getSection("ImportExportAction"); if (wizardSettings == null) { 166 wizardSettings = workbenchSettings 167 .addNewSection("ImportExportAction"); } 169 wizard.setDialogSettings(wizardSettings); 170 wizard.setForcePreviousAndNextButtons(true); 171 172 Shell parent = workbenchWindow.getShell(); 173 WizardDialog dialog = new WizardDialog(parent, wizard); 174 dialog.create(); 175 dialog.getShell().setSize( 176 Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), 177 SIZING_WIZARD_HEIGHT); 178 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 179 IWorkbenchHelpContextIds.EXPORT_WIZARD); 180 dialog.open(); 181 } 182 183 189 public void setSelection(IStructuredSelection selection) { 190 selectionChanged(selection); 191 } 192 193 197 public void dispose() { 198 if (workbenchWindow == null) { 199 return; 201 } 202 tracker.dispose(); 203 workbenchWindow.getSelectionService().removeSelectionListener( 204 selectionListener); 205 workbenchWindow = null; 206 } 207 } 208 | Popular Tags |