View | Details | Raw Unified | Return to bug 310437 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (+4 lines)
Lines 391-398 Link Here
391
391
392
	public static String ImportActionGroup_binaryWithLinkedContent;
392
	public static String ImportActionGroup_binaryWithLinkedContent;
393
393
394
	public static String ImportActionGroup_cannot_import;
395
394
	public static String ImportActionGroup_importContributingPlugin;
396
	public static String ImportActionGroup_importContributingPlugin;
395
397
398
	public static String ImportActionGroup_Repository_project;
399
396
	public static String InformationSection_0;
400
	public static String InformationSection_0;
397
401
398
	public static String InformationSection_1;
402
	public static String InformationSection_1;
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (+2 lines)
Lines 1045-1051 Link Here
1045
TemplateSelectionPage_column_point = Extension Point
1045
TemplateSelectionPage_column_point = Extension Point
1046
1046
1047
ImportActionGroup_binaryWithLinkedContent=Binary Project with &Linked Content
1047
ImportActionGroup_binaryWithLinkedContent=Binary Project with &Linked Content
1048
ImportActionGroup_cannot_import=The selected plug-ins cannot be imported from a repository.
1048
ImportActionGroup_importContributingPlugin=&Import Contributing Plug-in as
1049
ImportActionGroup_importContributingPlugin=&Import Contributing Plug-in as
1050
ImportActionGroup_Repository_project=&Repository Project...
1049
1051
1050
####
1052
####
1051
1053
(-)src/org/eclipse/pde/internal/ui/views/plugins/ImportActionGroup.java (-5 / +46 lines)
Lines 10-25 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.views.plugins;
11
package org.eclipse.pde.internal.ui.views.plugins;
12
12
13
import java.util.ArrayList;
13
import java.util.*;
14
import java.util.Iterator;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.jface.action.*;
15
import org.eclipse.jface.action.*;
16
import org.eclipse.jface.dialogs.MessageDialog;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.wizard.WizardDialog;
18
import org.eclipse.pde.core.plugin.*;
20
import org.eclipse.pde.core.plugin.*;
21
import org.eclipse.pde.internal.core.importing.provisional.BundleImportDescription;
22
import org.eclipse.pde.internal.core.importing.provisional.IBundleImporterDelegate;
23
import org.eclipse.pde.internal.core.project.BundleProjectService;
24
import org.eclipse.pde.internal.ui.PDEPlugin;
19
import org.eclipse.pde.internal.ui.PDEUIMessages;
25
import org.eclipse.pde.internal.ui.PDEUIMessages;
20
import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation;
26
import org.eclipse.pde.internal.ui.wizards.imports.*;
21
import org.eclipse.pde.internal.ui.wizards.imports.PluginImportWizard;
22
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.ui.actions.ActionContext;
29
import org.eclipse.ui.actions.ActionContext;
24
import org.eclipse.ui.actions.ActionGroup;
30
import org.eclipse.ui.actions.ActionGroup;
25
31
Lines 42-47 Link Here
42
				case PluginImportOperation.IMPORT_WITH_SOURCE :
48
				case PluginImportOperation.IMPORT_WITH_SOURCE :
43
					setText(PDEUIMessages.PluginsView_asSourceProject);
49
					setText(PDEUIMessages.PluginsView_asSourceProject);
44
					break;
50
					break;
51
				case PluginImportOperation.IMPORT_FROM_REPOSITORY :
52
					setText(PDEUIMessages.ImportActionGroup_Repository_project);
53
					break;
45
			}
54
			}
46
		}
55
		}
47
56
Lines 64-69 Link Here
64
			importMenu.add(new ImportAction(PluginImportOperation.IMPORT_BINARY, sSelection));
73
			importMenu.add(new ImportAction(PluginImportOperation.IMPORT_BINARY, sSelection));
65
			importMenu.add(new ImportAction(PluginImportOperation.IMPORT_BINARY_WITH_LINKS, sSelection));
74
			importMenu.add(new ImportAction(PluginImportOperation.IMPORT_BINARY_WITH_LINKS, sSelection));
66
			importMenu.add(new ImportAction(PluginImportOperation.IMPORT_WITH_SOURCE, sSelection));
75
			importMenu.add(new ImportAction(PluginImportOperation.IMPORT_WITH_SOURCE, sSelection));
76
			importMenu.add(new ImportAction(PluginImportOperation.IMPORT_FROM_REPOSITORY, sSelection));
67
			menu.add(importMenu);
77
			menu.add(importMenu);
68
		}
78
		}
69
	}
79
	}
Lines 79-86 Link Here
79
		if (display == null)
89
		if (display == null)
80
			display = Display.getDefault();
90
			display = Display.getDefault();
81
		IPluginModelBase[] models = (IPluginModelBase[]) externalModels.toArray(new IPluginModelBase[externalModels.size()]);
91
		IPluginModelBase[] models = (IPluginModelBase[]) externalModels.toArray(new IPluginModelBase[externalModels.size()]);
92
		if (importType == PluginImportOperation.IMPORT_FROM_REPOSITORY) {
93
			Map importMap = getImportDescriptions(display.getActiveShell(), models);
94
			if (importMap != null) {
95
				RepositoryImportWizard wizard = new RepositoryImportWizard(importMap);
96
				WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);
97
				dialog.open();
98
			}
99
		} else {
100
			PluginImportWizard.doImportOperation(display.getActiveShell(), importType, models, false);
101
		}
102
	}
82
103
83
		PluginImportWizard.doImportOperation(display.getActiveShell(), importType, models, false);
104
	/**
105
	 * Return a map of {@link IBundleImporterDelegate} > Array of {@link BundleImportDescription} to be imported.
106
	 * 
107
	 * @param shell shell to open message dialogs on, if required
108
	 * @param models candidate models
109
	 * @return  map of importer delegates to import descriptions
110
	 */
111
	private Map getImportDescriptions(Shell shell, IPluginModelBase[] models) {
112
		BundleProjectService service = (BundleProjectService) BundleProjectService.getDefault();
113
		try {
114
			Map descriptions = service.getImportDescriptions(models); // all possible descriptions
115
			if (!descriptions.isEmpty()) {
116
				return descriptions;
117
			}
118
			// no applicable importers for selected models
119
			MessageDialog.openInformation(shell, PDEUIMessages.ImportWizard_title, PDEUIMessages.ImportActionGroup_cannot_import);
120
		} catch (CoreException e) {
121
			PDEPlugin.log(e);
122
			MessageDialog.openError(shell, PDEUIMessages.ImportWizard_title, e.getMessage());
123
		}
124
		return null;
84
	}
125
	}
85
126
86
	public static boolean canImport(IStructuredSelection selection) {
127
	public static boolean canImport(IStructuredSelection selection) {
(-)src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java (-8 / +10 lines)
Lines 106-112 Link Here
106
		if (!page1.finishPages()) {
106
		if (!page1.finishPages()) {
107
			return false;
107
			return false;
108
		}
108
		}
109
		doImportOperation(getShell(), page1.getImportType(), models, page2.forceAutoBuild(), launchedConfiguration > 0, page1.getAlternateSourceLocations(), page1.getImportDescriptions());
109
		doImportOperation(page1.getImportType(), models, page2.forceAutoBuild(), launchedConfiguration > 0, page1.getAlternateSourceLocations(), page1.getImportDescriptions());
110
		return true;
110
		return true;
111
	}
111
	}
112
112
Lines 151-171 Link Here
151
	}
151
	}
152
152
153
	public static void doImportOperation(Shell shell, int importType, IPluginModelBase[] models, boolean forceAutobuild) {
153
	public static void doImportOperation(Shell shell, int importType, IPluginModelBase[] models, boolean forceAutobuild) {
154
		doImportOperation(shell, importType, models, forceAutobuild, false, null, null);
154
		doImportOperation(importType, models, forceAutobuild, false, null, null);
155
	}
155
	}
156
156
157
	/**
157
	/**
158
	 * Performs the import.
158
	 * 
159
	 * 
159
	 * @param shell
160
	 * @param importType one of the import operation types
160
	 * @param importType
161
	 * @param models models being imported
161
	 * @param models
162
	 * @param forceAutobuild whether to force a build after the import
162
	 * @param forceAutobuild
163
	 * @param launchedConfiguration if there is a launched target currently running 
163
	 * @param launchedConfiguration
164
	 * @param alternateSource used to locate source attachments or <code>null</code> if default
164
	 * @param alternateSource used to locate source attachments or <code>null</code> if default
165
	 * 	source locations should be used (from active target platform).
165
	 * 	source locations should be used (from active target platform).
166
	 * @param importerToDescriptions map of bundle importers to import descriptions if importing
167
	 *  from a repository, else <code>null</code>
166
	 *  
168
	 *  
167
	 */
169
	 */
168
	private static void doImportOperation(Shell shell, int importType, IPluginModelBase[] models, boolean forceAutobuild, boolean launchedConfiguration, SourceLocationManager alternateSource, Map importerToDescriptions) {
170
	public static void doImportOperation(int importType, IPluginModelBase[] models, boolean forceAutobuild, boolean launchedConfiguration, SourceLocationManager alternateSource, Map importerToDescriptions) {
169
		PluginImportOperation job = new PluginImportOperation(models, importType, forceAutobuild);
171
		PluginImportOperation job = new PluginImportOperation(models, importType, forceAutobuild);
170
		job.setImportDescriptions(importerToDescriptions);
172
		job.setImportDescriptions(importerToDescriptions);
171
		job.setAlternateSource(alternateSource);
173
		job.setAlternateSource(alternateSource);
(-)src/org/eclipse/pde/internal/ui/wizards/imports/RepositoryImportWizard.java (+149 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.wizards.imports;
12
13
import java.util.*;
14
import java.util.Map.Entry;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.jface.dialogs.IDialogSettings;
17
import org.eclipse.jface.wizard.IWizardPage;
18
import org.eclipse.jface.wizard.Wizard;
19
import org.eclipse.pde.core.plugin.IPluginModelBase;
20
import org.eclipse.pde.internal.core.importing.IBundleImporter;
21
import org.eclipse.pde.internal.core.importing.provisional.BundleImportDescription;
22
import org.eclipse.pde.internal.core.project.BundleProjectService;
23
import org.eclipse.pde.internal.ui.*;
24
import org.eclipse.pde.internal.ui.provisional.IBundeImportWizardPage;
25
26
/**
27
 * Wizard to import plug-ins from a repository.
28
 * 
29
 * @since 3.6
30
 */
31
public class RepositoryImportWizard extends Wizard {
32
33
	/**
34
	 * Map of import delegates to import descriptions as provided by the {@link BundleProjectService}
35
	 */
36
	private Map fImportMap;
37
38
	/**
39
	 * Map of importer identifier to associated wizard import page
40
	 */
41
	private Map fIdToPages = new HashMap();
42
43
	private static final String STORE_SECTION = "RepositoryImportWizard"; //$NON-NLS-1$
44
45
	/**
46
	 * Map of import delegates to import descriptions.
47
	 * 
48
	 * @param importMap
49
	 */
50
	public RepositoryImportWizard(Map importMap) {
51
		IDialogSettings masterSettings = PDEPlugin.getDefault().getDialogSettings();
52
		setDialogSettings(getSettingsSection(masterSettings));
53
		setDefaultPageImageDescriptor(PDEPluginImages.DESC_PLUGIN_IMPORT_WIZ);
54
		setWindowTitle(PDEUIMessages.ImportWizard_title);
55
		fImportMap = importMap;
56
	}
57
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
60
	 */
61
	public void addPages() {
62
		Iterator iterator = fImportMap.entrySet().iterator();
63
		while (iterator.hasNext()) {
64
			Entry entry = (Entry) iterator.next();
65
			IBundleImporter importer = (IBundleImporter) entry.getKey();
66
			BundleImportDescription[] descriptions = (BundleImportDescription[]) entry.getValue();
67
			IBundeImportWizardPage page = (IBundeImportWizardPage) fIdToPages.get(importer.getId());
68
			if (page == null) {
69
				page = getImportPage(importer.getId());
70
				if (page != null) {
71
					fIdToPages.put(importer.getId(), page);
72
					addPage(page);
73
					page.setSelection(descriptions);
74
				}
75
			}
76
		}
77
	}
78
79
	/**
80
	 * Creates and returns a wizard page associated with the given bundle importer extension identifier
81
	 * or <code>null</code> of none.
82
	 * 
83
	 * @param importerId org.eclipse.pde.core.bundleImporters extension identifier
84
	 * @return associated bundle import wizard page or <code>null</code>
85
	 */
86
	private IBundeImportWizardPage getImportPage(String importerId) {
87
		IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(IPDEUIConstants.EXTENSION_POINT_BUNDLE_IMPORT_PAGES);
88
		if (point != null) {
89
			IConfigurationElement[] infos = point.getConfigurationElements();
90
			for (int i = 0; i < infos.length; i++) {
91
				IConfigurationElement element = infos[i];
92
				String id = element.getAttribute("bundleImporter"); //$NON-NLS-1$
93
				if (id != null && importerId.equals(id)) {
94
					try {
95
						return (IBundeImportWizardPage) element.createExecutableExtension("class"); //$NON-NLS-1$
96
					} catch (CoreException e) {
97
						PDEPlugin.log(e);
98
					}
99
				}
100
			}
101
		}
102
		return null;
103
	}
104
105
	private IDialogSettings getSettingsSection(IDialogSettings master) {
106
		IDialogSettings setting = master.getSection(STORE_SECTION);
107
		if (setting == null) {
108
			setting = master.addNewSection(STORE_SECTION);
109
		}
110
		return setting;
111
	}
112
113
	/* (non-Javadoc)
114
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
115
	 */
116
	public boolean performFinish() {
117
		// collect the bundle descriptions from each page and import
118
		Map importMap = new HashMap();
119
		List plugins = new ArrayList();
120
		IWizardPage[] pages = getPages();
121
		for (int i = 0; i < pages.length; i++) {
122
			IBundeImportWizardPage page = (IBundeImportWizardPage) pages[i];
123
			if (page.finish()) {
124
				BundleImportDescription[] descriptions = page.getSelection();
125
				if (descriptions != null && descriptions.length > 0) {
126
					for (int j = 0; j < descriptions.length; j++) {
127
						BundleImportDescription description = descriptions[j];
128
						if (j == 0) {
129
							Object importer = description.getProperty(BundleProjectService.BUNDLE_IMPORTER);
130
							if (importer != null) {
131
								importMap.put(importer, descriptions);
132
							}
133
						}
134
						Object plugin = description.getProperty(BundleProjectService.PLUGIN);
135
						if (plugin != null) {
136
							plugins.add(plugin);
137
						}
138
					}
139
				}
140
			} else {
141
				return false;
142
			}
143
		}
144
		if (!importMap.isEmpty()) {
145
			PluginImportWizard.doImportOperation(PluginImportOperation.IMPORT_FROM_REPOSITORY, (IPluginModelBase[]) plugins.toArray(new IPluginModelBase[plugins.size()]), false, false, null, importMap);
146
		}
147
		return true;
148
	}
149
}

Return to bug 310437