1 54 55 package com.mullassery.act.gui; 56 57 import java.awt.event.ActionEvent ; 58 59 import javax.swing.AbstractAction ; 60 61 import org.w3c.dom.Element ; 62 63 import com.mullassery.act.ACTException; 64 import com.mullassery.act.util.GUIUtil; 65 66 71 public class OpenTaskAction extends AbstractAction { 72 private ACT act; 73 private String task; 74 private Element vals; 75 private boolean cloneNode; 76 77 OpenTaskAction(ACT act, Element values) throws ACTException { 78 this(act, values, true); 79 } 80 81 OpenTaskAction(ACT act, Element values, boolean cloneNode) throws ACTException { 82 if (values == null || !values.getNodeName().equals("task")) 83 throw new IllegalArgumentException ("Only <task/> Elements are accepted."); 84 vals = values; 85 this.cloneNode = cloneNode; 86 String display = vals.getAttribute(GUIUtil.TASK_DISPLAY); 87 this.task = vals.getAttribute(GUIUtil.TASK_NAME); 88 if ((display == null || display.length() < 1) && (task == null || task.length() < 1)) 89 throw new IllegalArgumentException ("<task/> element does not have any name!"); 90 91 if (task == null || task.length() < 1) { 92 task = display.toLowerCase(); vals.setAttribute(GUIUtil.TASK_NAME, task); 94 } 95 96 if (display == null || display.length() < 1) { 97 display = task; 98 vals.setAttribute(GUIUtil.TASK_DISPLAY, display); 99 } 100 101 this.putValue(NAME, display); 102 this.act = act; 103 } 104 105 public void actionPerformed(ActionEvent actionEvent) { 106 Element tsk = vals; 107 if (cloneNode) { 108 tsk = vals.getOwnerDocument().createElement(vals.getNodeName()); 109 tsk.setAttribute(GUIUtil.TASK_DISPLAY, vals.getAttribute(GUIUtil.TASK_DISPLAY)); 110 tsk.setAttribute(GUIUtil.TASK_NAME, vals.getAttribute(GUIUtil.TASK_NAME)); 111 String cls = vals.getAttribute(GUIUtil.TASK_CLASS); 112 if (cls != null && cls.length() > 0) 113 tsk.setAttribute(GUIUtil.TASK_CLASS, vals.getAttribute(GUIUtil.TASK_CLASS)); 114 } 115 116 try { 117 act.createTaskPanel(tsk); 118 } catch (Exception ex) { 119 GUIUtil.showErrorMessage( 120 act, 121 "Failed opening " 122 + task 123 + " task " 124 + ex.getMessage() 125 + ". Check if the classes and dependent libraries if any is avaiable in the class path"); 126 } 127 } 128 } | Popular Tags |