01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.target;
11:
12: import java.lang.reflect.InvocationTargetException;
13:
14: import org.eclipse.core.resources.IFile;
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.core.runtime.IProgressMonitor;
17: import org.eclipse.jface.viewers.ISelection;
18: import org.eclipse.jface.viewers.StructuredSelection;
19: import org.eclipse.pde.internal.core.ICoreConstants;
20: import org.eclipse.pde.internal.core.PDECore;
21: import org.eclipse.pde.internal.core.itarget.ILocationInfo;
22: import org.eclipse.pde.internal.core.itarget.ITarget;
23: import org.eclipse.pde.internal.core.itarget.ITargetModel;
24: import org.eclipse.pde.internal.core.target.WorkspaceTargetModel;
25: import org.eclipse.pde.internal.ui.IPDEUIConstants;
26: import org.eclipse.pde.internal.ui.PDEPlugin;
27: import org.eclipse.swt.widgets.Display;
28: import org.eclipse.ui.IWorkbenchPage;
29: import org.eclipse.ui.IWorkbenchPart;
30: import org.eclipse.ui.IWorkbenchWindow;
31: import org.eclipse.ui.PartInitException;
32: import org.eclipse.ui.actions.WorkspaceModifyOperation;
33: import org.eclipse.ui.ide.IDE;
34: import org.eclipse.ui.part.ISetSelectionTarget;
35:
36: public class BaseTargetDefinitionOperation extends
37: WorkspaceModifyOperation {
38:
39: private IFile fFile;
40:
41: public BaseTargetDefinitionOperation(IFile file) {
42: fFile = file;
43: }
44:
45: protected void execute(IProgressMonitor monitor)
46: throws CoreException, InvocationTargetException,
47: InterruptedException {
48: WorkspaceTargetModel model = new WorkspaceTargetModel(fFile,
49: false);
50: initializeTarget(model);
51: model.save();
52: model.dispose();
53: openFile();
54: monitor.done();
55: }
56:
57: protected void openFile() {
58: Display.getCurrent().asyncExec(new Runnable() {
59: public void run() {
60: IWorkbenchWindow ww = PDEPlugin
61: .getActiveWorkbenchWindow();
62: if (ww == null) {
63: return;
64: }
65: IWorkbenchPage page = ww.getActivePage();
66: if (page == null || !fFile.exists())
67: return;
68: IWorkbenchPart focusPart = page.getActivePart();
69: if (focusPart instanceof ISetSelectionTarget) {
70: ISelection selection = new StructuredSelection(
71: fFile);
72: ((ISetSelectionTarget) focusPart)
73: .selectReveal(selection);
74: }
75: try {
76: IDE.openEditor(page, fFile,
77: IPDEUIConstants.TARGET_EDITOR_ID);
78: } catch (PartInitException e) {
79: }
80: }
81: });
82: }
83:
84: protected void initializeTarget(ITargetModel model) {
85: ITarget target = model.getTarget();
86: ILocationInfo info = model.getFactory().createLocation();
87: info.setPath(PDECore.getDefault().getPluginPreferences()
88: .getString(ICoreConstants.PLATFORM_PATH));
89: info.setDefault(true);
90: target.setLocationInfo(info);
91: target.setUseAllPlugins(true);
92: }
93:
94: }
|