Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 210529 | Differences between
and this patch

Collapse All | Expand All

(-)src_samples/org/eclipse/pde/internal/ui/samples/ShowSampleAction.java (-22 / +56 lines)
Lines 11-24 Link Here
11
package org.eclipse.pde.internal.ui.samples;
11
package org.eclipse.pde.internal.ui.samples;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.net.URI;
15
import java.net.URISyntaxException;
16
import java.util.Collection;
14
import java.util.Properties;
17
import java.util.Properties;
15
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.equinox.p2.core.IProvisioningAgent;
20
import org.eclipse.equinox.p2.core.ProvisionException;
21
import org.eclipse.equinox.p2.engine.IProfile;
22
import org.eclipse.equinox.p2.engine.IProfileRegistry;
23
import org.eclipse.equinox.p2.operations.InstallOperation;
24
import org.eclipse.equinox.p2.operations.ProvisioningJob;
25
import org.eclipse.equinox.p2.query.*;
26
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
27
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
28
import org.eclipse.equinox.p2.ui.ProvisioningUI;
16
import org.eclipse.jface.action.Action;
29
import org.eclipse.jface.action.Action;
17
import org.eclipse.jface.dialogs.MessageDialog;
30
import org.eclipse.jface.dialogs.MessageDialog;
18
import org.eclipse.jface.operation.IRunnableWithProgress;
31
import org.eclipse.jface.operation.IRunnableWithProgress;
19
import org.eclipse.jface.window.Window;
32
import org.eclipse.jface.window.Window;
20
import org.eclipse.jface.wizard.WizardDialog;
33
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.pde.internal.core.util.VersionUtil;
22
import org.eclipse.pde.internal.ui.PDEPlugin;
34
import org.eclipse.pde.internal.ui.PDEPlugin;
23
import org.eclipse.pde.internal.ui.PDEUIMessages;
35
import org.eclipse.pde.internal.ui.PDEUIMessages;
24
import org.eclipse.swt.widgets.Shell;
36
import org.eclipse.swt.widgets.Shell;
Lines 26-35 Link Here
26
import org.eclipse.ui.WorkbenchException;
38
import org.eclipse.ui.WorkbenchException;
27
import org.eclipse.ui.intro.IIntroSite;
39
import org.eclipse.ui.intro.IIntroSite;
28
import org.eclipse.ui.intro.config.*;
40
import org.eclipse.ui.intro.config.*;
29
import org.eclipse.update.configurator.ConfiguratorUtils;
30
import org.eclipse.update.configurator.IPlatformConfiguration;
31
import org.eclipse.update.standalone.InstallCommand;
32
import org.osgi.framework.Version;
33
41
34
public class ShowSampleAction extends Action implements IIntroAction {
42
public class ShowSampleAction extends Action implements IIntroAction {
35
	private static final String SAMPLE_FEATURE_ID = "org.eclipse.sdk.samples"; //$NON-NLS-1$
43
	private static final String SAMPLE_FEATURE_ID = "org.eclipse.sdk.samples"; //$NON-NLS-1$
Lines 120-147 Link Here
120
	}
128
	}
121
129
122
	private boolean checkFeature() {
130
	private boolean checkFeature() {
123
		IPlatformConfiguration config = ConfiguratorUtils.getCurrentPlatformConfiguration();
131
		IProvisioningAgent agent = getProvisioningAgent();
124
		IPlatformConfiguration.IFeatureEntry[] features = config.getConfiguredFeatureEntries();
132
		IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
125
		Version sampleVersion = new Version(SAMPLE_FEATURE_VERSION);
133
		IProfile profile = registry.getProfile(IProfileRegistry.SELF);
126
		for (int i = 0; i < features.length; i++) {
134
		return profile.query(getSampleFeatureQuery(), null).isEmpty();
127
			String id = features[i].getFeatureIdentifier();
135
	}
128
			if (SAMPLE_FEATURE_ID.equals(id)) {
136
129
				String version = features[i].getFeatureVersion();
137
	IQuery getSampleFeatureQuery() {
130
				Version fversion = Version.parseVersion(version);
138
		return QueryUtil.createIUQuery(SAMPLE_FEATURE_ID, org.eclipse.equinox.p2.metadata.Version.parseVersion(SAMPLE_FEATURE_VERSION));
131
				if (VersionUtil.isCompatibleWith(fversion, sampleVersion))
132
					return true;
133
			}
134
		}
135
		return false;
136
	}
139
	}
137
140
138
	private boolean downloadFeature() {
141
	private boolean downloadFeature() {
139
		IRunnableWithProgress op = new IRunnableWithProgress() {
142
		IRunnableWithProgress op = new IRunnableWithProgress() {
140
			public void run(IProgressMonitor monitor) throws InvocationTargetException {
143
			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
141
				try {
144
				try {
142
					InstallCommand command = new InstallCommand(SAMPLE_FEATURE_ID, SAMPLE_FEATURE_VERSION, UPDATE_SITE, null, "false"); //$NON-NLS-1$
145
					SubMonitor sub = SubMonitor.convert(monitor, 100);
143
					command.run(monitor);
146
					InstallOperation operation = createInstallOperation(sub.newChild(10));
144
					command.applyChangesNow();
147
					operation.resolveModal(sub.newChild(20));
148
					IStatus status = operation.getResolutionResult();
149
					if (status.getSeverity() == IStatus.CANCEL) {
150
						throw new InterruptedException();
151
					} else if (!(status.isOK() || status.getSeverity() == IStatus.INFO)) {
152
						throw new CoreException(status);
153
					}
154
					ProvisioningJob job = operation.getProvisioningJob(null);
155
					status = job.runModal(sub.newChild(70));
156
					if (!(status.isOK() || status.getSeverity() == IStatus.INFO)) {
157
						throw new CoreException(status);
158
					}
145
				} catch (Exception e) {
159
				} catch (Exception e) {
146
					throw new InvocationTargetException(e);
160
					throw new InvocationTargetException(e);
147
				}
161
				}
Lines 157-160 Link Here
157
		}
171
		}
158
		return true;
172
		return true;
159
	}
173
	}
174
175
	protected Collection findSampleIUs(IProvisioningAgent agent, URI location, SubMonitor monitor) throws ProvisionException {
176
		IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
177
		IMetadataRepository repository = manager.loadRepository(location, monitor.newChild(5));
178
		IQueryResult result = repository.query(getSampleFeatureQuery(), monitor.newChild(5));
179
		return result.toUnmodifiableSet();
180
	}
181
182
	protected IProvisioningAgent getProvisioningAgent() {
183
		return null;
184
	}
185
186
	InstallOperation createInstallOperation(SubMonitor monitor) throws URISyntaxException, ProvisionException {
187
		IProvisioningAgent agent = getProvisioningAgent();
188
		URI repositoryLocation = new URI(UPDATE_SITE);
189
		Collection sampleIUs = findSampleIUs(agent, repositoryLocation, monitor);
190
		URI[] repos = new URI[] {repositoryLocation};
191
		InstallOperation operation = ProvisioningUI.getDefaultUI().getInstallOperation(sampleIUs, repos);
192
		return operation;
193
	}
160
}
194
}

Return to bug 210529