KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > definition > actions > UpdatePackage


1 package org.enhydra.shark.swingclient.workflowadmin.definition.actions;
2
3
4 import org.enhydra.shark.api.client.wfbase.*;
5
6 import org.enhydra.shark.api.client.wfservice.*;
7
8 import java.awt.event.*;
9 import javax.swing.*;
10 import java.util.*;
11
12 import org.enhydra.shark.swingclient.*;
13 import org.enhydra.shark.swingclient.workflowadmin.*;
14 import org.enhydra.shark.swingclient.workflowadmin.definition.*;
15
16 /**
17  * Updates selected package from external repository.
18  *
19  * @author Sasa Bojanic
20  * @version 1.0
21  */

22 public class UpdatePackage extends ActionBase {
23
24    public UpdatePackage (PackageManagement pdm) {
25       super(pdm);
26    }
27
28    public void actionPerformed(ActionEvent e) {
29       PackageManagement pdm=(PackageManagement)actionPanel;
30       SharkAdmin workflowAdmin=pdm.getWorkflowAdmin();
31
32       // check if package container is referenced by some other package
33
String JavaDoc selPkgId=pdm.getSelectedPackageId();
34       if (selPkgId==null) return;
35       try {
36          boolean ipr=SharkAdmin.getPackageAmin().isPackageReferenced(selPkgId);
37
38          if (ipr) {
39             String JavaDoc msg=ResourceManager.getLanguageDependentString("MessagePackageIsReferencedDoYouWantToProceed");
40             int r=JOptionPane.showConfirmDialog(pdm.getWindow(),msg,
41                   workflowAdmin.getAppTitle(),JOptionPane.YES_NO_OPTION);
42             if (r==JOptionPane.NO_OPTION) return;
43          }
44       } catch (Exception JavaDoc be) {
45          String JavaDoc errMsg=ResourceManager.getLanguageDependentString("ErrorTheUpdateOfSelectedPackageIsNotAllowedAtTheMoment");
46          JOptionPane.showMessageDialog(workflowAdmin.getFrame(),errMsg,
47                workflowAdmin.getAppTitle(),JOptionPane.ERROR_MESSAGE);
48          return;
49       }
50
51       // Filter the list of posible package files to display only the ones
52
// with the same id as the one user want to update
53
List allPackages=new ArrayList();
54       try {
55          Map allPkgs=SharkAdmin.getRepositoryManager().getPackagePathToIdMapping();
56          if (allPkgs!=null) {
57             for (Iterator i=allPkgs.entrySet().iterator(); i.hasNext();) {
58                Map.Entry me=(Map.Entry)i.next();
59                if (me.getValue().toString().equals(selPkgId)) {
60                   allPackages.add(new NameValueStringMap(me.getKey().toString(),me.getValue().toString()));
61                }
62             }
63          }
64       } catch (Exception JavaDoc ex) {
65          String JavaDoc errMsg=ResourceManager.getLanguageDependentString("ErrorTheUpdateOfSelectedPackageIsNotAllowedAtTheMoment");
66          JOptionPane.showMessageDialog(workflowAdmin.getFrame(),errMsg,
67                workflowAdmin.getAppTitle(),JOptionPane.ERROR_MESSAGE);
68          return;
69       }
70
71       SelectPackage spd=new SelectPackage (this,pdm.getWindow(),allPackages);
72       spd.showDialog();
73    }
74
75    public void updatePackage (String JavaDoc pkgId,String JavaDoc newPkgFilename) {
76
77       PackageManagement pdm=(PackageManagement)actionPanel;
78       SharkAdmin workflowAdmin=pdm.getWorkflowAdmin();
79       workflowAdmin.stopRefresher();
80       // wait if admin is in the process of refreshing
81
while (workflowAdmin.isRefresherActive());
82       String JavaDoc selPkgId=pdm.getSelectedPackageId();
83       if (selPkgId!=null) {
84          SplashScreen ss=workflowAdmin.getSplashScreen();
85          ss.show("WaitImage",
86                workflowAdmin.getFullUserName(),
87                ResourceManager.getLanguageDependentString("MessagePleaseWait"));
88
89          String JavaDoc errMsg=null;
90          String JavaDoc xpdlReport="Something went wrong";
91          try {
92             try {
93                SharkAdmin.getPackageAmin().updatePackage(pkgId,newPkgFilename);
94             } catch (BaseException be){
95                   throw new PackageUpdateNotAllowed();
96             }
97          } catch (PackageInvalid ipe) {
98             errMsg=ResourceManager.getLanguageDependentString("ErrorTheUpdaterPackageIsInvalid");
99             xpdlReport=ipe.getXPDLValidationErrors();
100          } catch (PackageUpdateNotAllowed puna) {
101             errMsg=ResourceManager.getLanguageDependentString("ErrorTheUpdateOfSelectedPackageIsNotAllowedAtTheMoment");
102          } catch (Exception JavaDoc ex) {
103             errMsg=ResourceManager.getLanguageDependentString("ErrorTheUpdateOfSelectedPackageFailed");
104          }
105          workflowAdmin.refreshAfterUpdate();
106          workflowAdmin.requestFocus();
107          ss.hide();
108
109          if (errMsg!=null) {
110             JOptionPane.showMessageDialog(workflowAdmin.getFrame(),errMsg,
111                   workflowAdmin.getAppTitle(),JOptionPane.ERROR_MESSAGE);
112             pdm.getWorkflowAdmin().showXPDLErrorsReport(xpdlReport);
113          }
114       }
115       workflowAdmin.startRefresher();
116    }
117
118 }
119
Popular Tags