1 package org.enhydra.shark.swingclient.workflowadmin.application; 2 3 import java.awt.*; 4 import java.util.*; 5 6 import javax.swing.*; 7 import javax.swing.table.*; 8 9 10 import org.enhydra.shark.api.client.wfservice.*; 11 12 import org.enhydra.jawe.xml.elements.*; 13 import org.enhydra.shark.swingclient.*; 14 import org.enhydra.shark.swingclient.workflowadmin.*; 15 import org.enhydra.shark.swingclient.workflowadmin.application.actions.*; 16 17 import org.enhydra.jawe.JaWE; 18 19 26 public class ApplicationMappingManagement extends ActionPanel { 27 28 private SharkAdmin workflowAdmin; 29 30 private TablePanel existingMappingsPanel; 31 32 private Map applicationKeyToApplication=new HashMap(); 33 34 public ApplicationMappingManagement (SharkAdmin wa) { 35 super(); 36 this.workflowAdmin=wa; 37 super.init(); 38 } 39 40 protected void createActions () { 41 defaultActions=new Action[] { 42 new AddApplicationMapping(this), 43 new RemoveApplicationMapping(this) 44 }; 45 } 46 47 protected Component createCenterComponent() { 48 Vector columnNames=new Vector(); 49 columnNames.add(ResourceManager.getLanguageDependentString("PackageIdKey")); 50 columnNames.add(ResourceManager.getLanguageDependentString("ProcessDefinitionIdKey")); 51 columnNames.add(ResourceManager.getLanguageDependentString("ApplicationIdKey")); 52 columnNames.add(ResourceManager.getLanguageDependentString("ApplicationNameKey")); 53 columnNames.add("-->"); 54 columnNames.add(ResourceManager.getLanguageDependentString("ToolAgentNameKey")); 55 columnNames.add(ResourceManager.getLanguageDependentString("UsernameKey")); 56 columnNames.add(ResourceManager.getLanguageDependentString("PasswordKey")); 57 columnNames.add(ResourceManager.getLanguageDependentString("ApplicationNameKey")); 58 columnNames.add(ResourceManager.getLanguageDependentString("ApplicationModeKey")); 59 existingMappingsPanel=new TablePanel(columnNames, true); 60 JTable t=existingMappingsPanel.getTable(); 61 TableColumnModel tcm=t.getColumnModel(); 62 TableColumn column=t.getColumnModel().getColumn(4); 63 column.setMaxWidth(30); 64 column.setMinWidth(30); 65 column.setPreferredWidth(30); 66 column.setResizable(false); 67 68 return existingMappingsPanel; 69 } 70 71 public void clear () { 72 applicationKeyToApplication.clear(); 73 existingMappingsPanel.removeAll(); 74 } 75 76 public synchronized void refresh (boolean mandatoryRefreshing) { 77 if (!(mandatoryRefreshing || isShowing())) return; 78 SharkConnection wcs=workflowAdmin.getService(); 79 if (wcs==null) return; 80 java.util.List allMappings=null; 81 82 try { 83 allMappings=new ArrayList(Arrays.asList(SharkAdmin.getApplicationMappingsAdmin().getApplicationMappings())); 84 } catch (Exception ex) { 85 System.out.println("Something went wrong during retrieval of mappings from engine"); 86 return; 87 } 88 Collection pkgs=JaWE.getInstance().getXMLInterface().getAllPackages(); 89 existingMappingsPanel.removeAll(); 90 applicationKeyToApplication.clear(); 91 92 createApplicationsMap(pkgs); 94 95 Iterator it=allMappings.iterator(); 97 while (it.hasNext()) { 98 ApplicationMap am=(ApplicationMap)it.next(); 99 try { 100 Vector v=new Vector(); 101 v.add(am.getPackageId()); 102 v.add(am.getProcessDefinitionId()); 103 v.add(am.getApplicationDefinitionId()); 104 Application app=((Application)applicationKeyToApplication. 105 get(WorkflowUtilities. 106 createParticipantOrApplicationKey( 107 am.getPackageId(), 108 am.getProcessDefinitionId(), 109 am.getApplicationDefinitionId()))); 110 if (app!=null) { 111 v.add(app.get("Name").toString()); 112 } else { 113 v.add(""); 114 } 115 v.add(""); 116 v.add(am.getToolAgentClassName()); 117 v.add(am.getUsername()); 118 v.add(am.getPassword()); 119 v.add(am.getApplicationName()); 120 v.add(am.getApplicationMode()); 121 existingMappingsPanel.addElement(v); 122 } catch (Exception ex) { 123 System.out.println("Incorrect vector size"); 124 } 125 } 126 } 127 128 private void createApplicationsMap (Collection packageColl) { 129 ArrayList allLoadedApplications=new ArrayList(); 130 try { 131 ApplicationMap[] maps=SharkAdmin.getApplicationMappingsAdmin().getAllApplications(); 132 for (int i=0; i<maps.length; i++) { 133 allLoadedApplications.add( 134 WorkflowUtilities.createParticipantOrApplicationKey( 135 maps[i].getPackageId(), 136 maps[i].getProcessDefinitionId(), 137 maps[i].getApplicationDefinitionId())); 138 } 139 } catch (Exception ex) { 140 } 141 142 if (allLoadedApplications.size()==0) return; 143 144 145 org.enhydra.jawe.xml.elements.Package pkg; 146 Iterator packages=packageColl.iterator(); 147 while (packages.hasNext()) { 148 pkg=(org.enhydra.jawe.xml.elements.Package)packages.next(); 149 Applications aps=(Applications)pkg.get("Applications"); 150 Iterator applications=aps.toCollection().iterator(); 151 while (applications.hasNext()) { 152 Application a=(Application)applications.next(); 153 String applicationKey=WorkflowUtilities.createParticipantOrApplicationKey( 154 pkg.get("Id").toString(),"",a.getID()); 155 if (allLoadedApplications.contains(applicationKey)) { 156 applicationKeyToApplication.put(applicationKey,a); 157 } 158 } 159 Iterator processes=((WorkflowProcesses)pkg.get("WorkflowProcesses")). 160 toCollection().iterator(); 161 while (processes.hasNext()) { 162 WorkflowProcess wp=(WorkflowProcess)processes.next(); 163 aps=(Applications)wp.get("Applications"); 164 applications=aps.toCollection().iterator(); 165 while (applications.hasNext()) { 166 Application a=(Application)applications.next(); 167 String applicationKey=WorkflowUtilities.createParticipantOrApplicationKey( 168 pkg.get("Id").toString(),wp.getID(),a.getID()); 169 if (allLoadedApplications.contains(applicationKey)) { 170 applicationKeyToApplication.put(applicationKey,a); 171 } 172 } 173 } 174 } 175 } 176 177 public SharkAdmin getWorkflowAdmin () { 178 return workflowAdmin; 179 } 180 181 public Map getApplicationKeyToApplication () { 182 return applicationKeyToApplication; 183 } 184 185 public TablePanel getExistingMappingsPanel () { 186 return existingMappingsPanel; 187 } 188 189 } 190 | Popular Tags |