KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.update.core.*;
17 import org.eclipse.update.core.model.*;
18 import org.eclipse.update.internal.core.*;
19 import org.eclipse.update.operations.*;
20
21 public class BatchInstallOperation
22     extends Operation
23     implements IBatchOperation {
24         
25     protected IInstallFeatureOperation[] operations;
26
27     public BatchInstallOperation(IInstallFeatureOperation[] operations) {
28         super();
29         this.operations = operations;
30     }
31
32     /* (non-Javadoc)
33      * @see org.eclipse.update.operations.IMultiOperation#getOperations()
34      */

35     public IFeatureOperation[] getOperations() {
36         return operations;
37     }
38
39     /* (non-Javadoc)
40      * @see org.eclipse.update.operations.IOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
41      */

42     public boolean execute(IProgressMonitor monitor, IOperationListener listener) throws CoreException, InvocationTargetException {
43         int installCount = 0;
44
45         if (operations == null || operations.length == 0)
46             return false;
47                     
48         IStatus status = OperationsManager.getValidator().validatePendingChanges(operations);
49         if (status != null && status.getCode() == IStatus.ERROR) {
50             throw new CoreException(status);
51         }
52         
53 // // Check for duplication conflicts
54
// ArrayList conflicts =
55
// DuplicateConflictsValidator.computeDuplicateConflicts(
56
// operations,
57
// config);
58
// if (conflicts != null) {
59
// boolean continueProcessing = false;
60
// if (listener != null)
61
// continueProcessing = listener.beforeExecute(this, conflicts);
62
// if (!continueProcessing)
63
// return false;
64
// }
65

66         OperationsManager.setInProgress(true);
67         if (monitor == null)
68             monitor = new NullProgressMonitor();
69             
70         try {
71             if (listener != null)
72                 listener.beforeExecute(this, null);
73             
74             monitor.beginTask(
75                 Messages.OperationsManager_installing,
76                 operations.length);
77             for (int i = 0; i < operations.length; i++) {
78                 SubProgressMonitor subMonitor =
79                     new SubProgressMonitor(
80                         monitor,
81                         1,
82                         SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
83
84                 operations[i].execute(subMonitor, listener);
85                 OperationsManager.addPendingOperation(operations[i]);
86
87                 operations[i].markProcessed();
88                 if (listener != null)
89                     listener.afterExecute(operations[i], null);
90
91                 //monitor.worked(1);
92
installCount++;
93             }
94             return SiteManager.getLocalSite().save();
95         } catch (InstallAbortedException e) {
96             // saves the current configuration
97
if (installCount > 0) {
98                 try {
99                     SiteManager.getLocalSite().save();
100                 } catch (CoreException ce) {
101                     UpdateUtils.logException(ce);
102                 }
103             }
104             throw new InvocationTargetException(e);
105         } catch (CoreException e) {
106             // saves the current configuration
107
if (installCount > 0) {
108                 try {
109                     SiteManager.getLocalSite().save();
110                 } catch (CoreException ce) {
111                     UpdateUtils.logException(ce);
112                 }
113             }
114             throw new InvocationTargetException(e);
115         } finally {
116             OperationsManager.setInProgress(false);
117             monitor.done();
118         }
119     }
120 }
121
Popular Tags