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 54 public class ImportResourcesAction extends BaseSelectionListenerAction 55 implements ActionFactory.IWorkbenchAction { 56 57 private static final int SIZING_WIZARD_WIDTH = 470; 58 59 private static final int SIZING_WIZARD_HEIGHT = 550; 60 61 65 private IWorkbenchWindow workbenchWindow; 66 67 71 private PerspectiveTracker tracker; 72 73 77 private final ISelectionListener selectionListener = new ISelectionListener() { 78 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 79 if (selection instanceof IStructuredSelection) { 80 IStructuredSelection structured = (IStructuredSelection) selection; 81 ImportResourcesAction.this.selectionChanged(structured); 82 } 83 } 84 }; 85 86 91 public ImportResourcesAction(IWorkbenchWindow window) { 92 super(WorkbenchMessages.ImportResourcesAction_text); 93 if (window == null) { 94 throw new IllegalArgumentException (); 95 } 96 this.workbenchWindow = window; 97 tracker = new PerspectiveTracker(window, this); 98 setToolTipText(WorkbenchMessages.ImportResourcesAction_toolTip); 99 setId("import"); window.getWorkbench().getHelpSystem().setHelp(this, 101 IWorkbenchHelpContextIds.IMPORT_ACTION); 102 workbenchWindow.getSelectionService().addSelectionListener( 104 selectionListener); 105 106 setImageDescriptor(WorkbenchImages 107 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_IMPORT_WIZ)); 108 } 109 110 116 public ImportResourcesAction(IWorkbench workbench) { 117 this(workbench.getActiveWorkbenchWindow()); 118 } 119 120 123 public void run() { 124 if (workbenchWindow == null) { 125 return; 127 } 128 ImportExportWizard wizard = new ImportExportWizard(ImportExportWizard.IMPORT); 129 IStructuredSelection selectionToPass; 130 ISelection workbenchSelection = workbenchWindow.getSelectionService() 132 .getSelection(); 133 if (workbenchSelection instanceof IStructuredSelection) { 134 selectionToPass = (IStructuredSelection) workbenchSelection; 135 } else { 136 selectionToPass = StructuredSelection.EMPTY; 137 } 138 139 wizard.init(workbenchWindow.getWorkbench(), selectionToPass); 140 IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault() 141 .getDialogSettings(); 142 IDialogSettings wizardSettings = workbenchSettings 143 .getSection("ImportExportAction"); if (wizardSettings == null) { 145 wizardSettings = workbenchSettings 146 .addNewSection("ImportExportAction"); } 148 wizard.setDialogSettings(wizardSettings); 149 wizard.setForcePreviousAndNextButtons(true); 150 151 Shell parent = workbenchWindow.getShell(); 152 WizardDialog dialog = new WizardDialog(parent, wizard); 153 dialog.create(); 154 dialog.getShell().setSize( 155 Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), 156 SIZING_WIZARD_HEIGHT); 157 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 158 IWorkbenchHelpContextIds.IMPORT_WIZARD); 159 dialog.open(); 160 } 161 162 168 public void setSelection(IStructuredSelection selection) { 169 selectionChanged(selection); 170 } 171 172 176 public void dispose() { 177 if (workbenchWindow == null) { 178 return; 180 } 181 tracker.dispose(); 182 workbenchWindow.getSelectionService().removeSelectionListener( 183 selectionListener); 184 workbenchWindow = null; 185 } 186 } 187 | Popular Tags |