KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > operations > BatchFeatureOperation


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.update.internal.operations;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.update.configuration.IConfiguredSite;
18 import org.eclipse.update.core.IFeature;
19 import org.eclipse.update.operations.IOperation;
20 import org.eclipse.update.operations.IOperationListener;
21
22 public abstract class BatchFeatureOperation extends Operation implements IBatchFeatureOperation {
23
24     private IFeature[] features;
25     private IConfiguredSite[] targetSites;
26     
27     
28     public BatchFeatureOperation(IConfiguredSite[] targetSites, IFeature[] features) {
29         super();
30         this.features = features;
31         this.targetSites = targetSites;
32     }
33     
34     public IFeature[] getFeatures() {
35         return features;
36     }
37
38     public IConfiguredSite[] getTargetSites() {
39         return targetSites;
40     }
41
42     public void setTargetSites(IConfiguredSite[] targetSites) {
43         this.targetSites = targetSites;
44         
45     }
46     
47     public boolean execute(IProgressMonitor pm, IOperationListener listener)
48         throws CoreException, InvocationTargetException JavaDoc {
49
50         if (getFeatures() == null || getFeatures().length == 0)
51             return false;
52         IOperation[] operations = new IOperation[getFeatures().length];
53         
54         for ( int i = 0; i < getFeatures().length; i ++) {
55             operations[i] = createOperation(getTargetSites()[i], getFeatures()[i]);
56         }
57         
58         boolean restartNeeded = false;
59
60         for ( int i = 0; i < operations.length; i ++) {
61             try {
62                 boolean status = operations[i].execute(pm, listener);
63                 if (status)
64                     restartNeeded = true;
65             } catch (Throwable JavaDoc t) {
66                 t.printStackTrace();
67             }
68         }
69
70         return restartNeeded;
71
72     }
73
74     protected abstract IOperation createOperation(IConfiguredSite targetSite, IFeature feature);
75
76 }
77
Popular Tags