KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > product > SynchronizationOperation


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.product;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.Status;
20 import org.eclipse.osgi.util.NLS;
21 import org.eclipse.pde.core.plugin.IPluginModelBase;
22 import org.eclipse.pde.core.plugin.PluginRegistry;
23 import org.eclipse.pde.internal.core.iproduct.IProduct;
24 import org.eclipse.pde.internal.ui.PDEUIMessages;
25 import org.eclipse.swt.widgets.Shell;
26
27
28 public class SynchronizationOperation extends ProductDefinitionOperation {
29
30     public SynchronizationOperation(IProduct product, Shell shell, IProject project) {
31         super(product, getPluginId(product), getProductId(product), product.getApplication(), shell, project);
32     }
33     
34     private static String JavaDoc getProductId(IProduct product) {
35         String JavaDoc full = product.getId();
36         int index = full.lastIndexOf('.');
37         return index != -1 ? full.substring(index + 1) : full;
38     }
39     
40     private static String JavaDoc getPluginId(IProduct product) {
41         String JavaDoc full = product.getId();
42         int index = full.lastIndexOf('.');
43         return index != -1 ? full.substring(0, index) : full;
44     }
45     
46     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
47         IPluginModelBase model = PluginRegistry.findModel(fPluginId);
48         if (model == null) {
49             String JavaDoc message = PDEUIMessages.SynchronizationOperation_noDefiningPlugin;
50             throw new InvocationTargetException JavaDoc(createCoreException(message));
51         }
52         
53         if (model.getUnderlyingResource() == null) {
54             String JavaDoc id = model.getPluginBase().getId();
55             String JavaDoc message = PDEUIMessages.SynchronizationOperation_externalPlugin;
56             throw new InvocationTargetException JavaDoc(createCoreException(NLS.bind(message, id)));
57         }
58         
59         super.run(monitor);
60     }
61     
62     private CoreException createCoreException(String JavaDoc message) {
63         IStatus status = new Status(IStatus.ERROR, "org.eclipse.pde.ui", IStatus.ERROR, message, null); //$NON-NLS-1$
64
return new CoreException(status);
65     }
66
67 }
68
Popular Tags