KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > actions > MoveUpParticipant


1 /*
2  * Author:
3  * Harald Meister harald.meister@abacus.ch
4  */

5
6 package org.enhydra.jawe.actions;
7
8 import java.awt.event.ActionEvent JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.Collections JavaDoc;
11 import java.util.Comparator JavaDoc;
12 import org.enhydra.jawe.AbstractEditor;
13 import org.enhydra.jawe.ProcessEditor;
14 import org.enhydra.jawe.WorkflowManager;
15 import org.enhydra.jawe.graph.Participant;
16
17 public class MoveUpParticipant extends ActionBase {
18    
19    public MoveUpParticipant (AbstractEditor editor) {
20       super(editor);
21    }
22    
23    public void actionPerformed(ActionEvent JavaDoc e) {
24       if (editor instanceof ProcessEditor) {
25          Object JavaDoc[] cells = editor.getGraph().getSelectionCells();
26          ArrayList JavaDoc gparts=new ArrayList JavaDoc();
27          for(int i=0;i<cells.length;i++){
28             gparts.add(cells[i]);
29          }
30          WorkflowManager dm=editor.getGraph().getWorkflowManager();
31          ParticipantComparator pc=new ParticipantComparator(dm);
32          Collections.sort(gparts,pc);//sort so that the move works correctly with mutliple selected participants
33
dm.moveParticipants(gparts.toArray(), true);
34       }
35    }
36    
37    //******************* PARTICIPANTCOMPARATOR CLASS **********************
38
/**
39     * Used to properly sort visual objects that represents Participant's
40     * contained within graph.
41     */

42    private static class ParticipantComparator implements Comparator JavaDoc {
43       WorkflowManager workflowManager;
44       public ParticipantComparator (WorkflowManager workflowManager) {
45          this.workflowManager=workflowManager;
46       }
47       
48       public int compare(Object JavaDoc o1, Object JavaDoc o2) {
49          Participant p1=(Participant)o1;
50          Participant p2=(Participant)o2;
51             int y1=workflowManager.getBounds(p1,null).getBounds().y;//HM, JGraph3.4.1
52
int y2=workflowManager.getBounds(p2,null).getBounds().y;//HM, JGraph3.4.1
53

54          return (y1<y2 ? -1 : (y1==y2 ? 0 : 1)); //sort that highest is first
55
}
56    }
57    //**************** END OF PARTICIPANTCOMPARATOR CLASS ******************
58
}
59
60
Popular Tags