]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/actions/JarImportWizardAction.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / actions / JarImportWizardAction.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2005, 2011 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 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.actions;
12
13import org.eclipse.jface.action.Action;
14import org.eclipse.jface.action.IAction;
15import org.eclipse.jface.viewers.ISelection;
16import org.eclipse.jface.viewers.ISelectionChangedListener;
17import org.eclipse.jface.viewers.IStructuredSelection;
18import org.eclipse.jface.viewers.SelectionChangedEvent;
19import org.eclipse.jface.wizard.WizardDialog;
20
21import org.eclipse.ui.IImportWizard;
22import org.eclipse.ui.IObjectActionDelegate;
23import org.eclipse.ui.IWorkbenchPart;
24import org.eclipse.ui.IWorkbenchWindow;
25import org.eclipse.ui.PlatformUI;
26
27import org.eclipse.jdt.core.IClasspathEntry;
28import org.eclipse.jdt.core.IPackageFragmentRoot;
29import org.eclipse.jdt.core.JavaModelException;
30
31import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
32import org.eclipse.jdt.internal.ui.JavaPlugin;
33import org.eclipse.jdt.internal.ui.jarimport.JarImportWizard;
34
35/**
36 * Combined action and action delegate for the jar import action.
37 *
38 * @since 3.2
39 */
40public class JarImportWizardAction extends Action implements IObjectActionDelegate, ISelectionChangedListener {
41
42 /** The wizard height */
43 public static final int SIZING_WIZARD_HEIGHT= 520;
44
45 /** The wizard width */
46 public static final int SIZING_WIZARD_WIDTH= 470;
47
48 /** The structured selection, or <code>null</code> */
49 private IStructuredSelection fSelection= null;
50
51 /** The active workbench part, or <code>null</code> */
52 private IWorkbenchPart fWorkbenchPart= null;
53
54 /**
55 * {@inheritDoc}
56 */
57 @Override
58 public void run() {
59 run(this);
60 }
61
62 /**
63 * {@inheritDoc}
64 */
65 public void run(final IAction action) {
66 if (fWorkbenchPart == null || fSelection == null)
67 return;
68 final IImportWizard wizard= new JarImportWizard(false);
69 final IWorkbenchWindow window= fWorkbenchPart.getSite().getWorkbenchWindow();
70 wizard.init(window.getWorkbench(), fSelection);
71 final WizardDialog dialog= new WizardDialog(window.getShell(), wizard);
72 dialog.create();
73 dialog.getShell().setSize(Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), SIZING_WIZARD_HEIGHT);
74 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IJavaHelpContextIds.JARIMPORT_WIZARD_PAGE);
75 dialog.open();
76 }
77
78 /**
79 * {@inheritDoc}
80 */
81 public void selectionChanged(final IAction action, final ISelection selection) {
82 fSelection= null;
83 if (selection instanceof IStructuredSelection) {
84 final IStructuredSelection structured= (IStructuredSelection) selection;
85 if (structured.size() == 1) {
86 final Object element= structured.getFirstElement();
87 if (element instanceof IPackageFragmentRoot) {
88 final IPackageFragmentRoot root= (IPackageFragmentRoot) element;
89 try {
90 final IClasspathEntry entry= root.getRawClasspathEntry();
91 if (JarImportWizard.isValidClassPathEntry(entry) && JarImportWizard.isValidJavaProject(root.getJavaProject())
92 && root.getResolvedClasspathEntry().getReferencingEntry() == null) {
93 fSelection= structured;
94 }
95 } catch (JavaModelException exception) {
96 JavaPlugin.log(exception);
97 }
98 }
99 }
100 }
101 action.setEnabled(fSelection != null);
102 }
103
104 /**
105 * {@inheritDoc}
106 */
107 public void selectionChanged(final SelectionChangedEvent event) {
108 selectionChanged(this, event.getSelection());
109 }
110
111 /**
112 * {@inheritDoc}
113 */
114 public void setActivePart(final IAction action, final IWorkbenchPart part) {
115 fWorkbenchPart= part;
116 }
117}