01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.bpel.nodes.actions;
20:
21: import org.netbeans.modules.bpel.nodes.actions.BpelNodeAction;
22: import org.netbeans.modules.bpel.editors.api.nodes.actions.ActionType;
23: import org.netbeans.modules.bpel.model.api.BPELElementsBuilder;
24: import org.netbeans.modules.bpel.model.api.BpelEntity;
25: import org.netbeans.modules.bpel.model.api.EventHandlers;
26: import org.netbeans.modules.bpel.model.api.For;
27: import org.netbeans.modules.bpel.model.api.OnAlarmEvent;
28: import org.netbeans.modules.bpel.model.api.OnAlarmPick;
29: import org.netbeans.modules.bpel.model.api.Pick;
30: import org.netbeans.modules.bpel.model.api.events.VetoException;
31: import org.openide.ErrorManager;
32: import org.openide.util.NbBundle;
33:
34: /**
35: *
36: * @author Vitaly Bychkov
37: * @version 28 March 2006
38: */
39: public class AddOnAlarmAction extends BpelNodeAction {
40: private static final long serialVersionUID = 1L;
41:
42: public static final String DEFAULT_FOR_VALUE = "'P0Y0M0DT0H0M0S'"; //NOI18N
43:
44: public AddOnAlarmAction() {
45: putValue(SHORT_DESCRIPTION, NbBundle.getMessage(getClass(),
46: "CTL_DESC_AddOnAlarmAction")); // NOI18N
47: }
48:
49: protected String getBundleName() {
50: return NbBundle.getMessage(getClass(), "CTL_AddOnAlarmAction"); // NOI18N
51: }
52:
53: public ActionType getType() {
54: return ActionType.ADD_ON_ALARM;
55: }
56:
57: protected void performAction(BpelEntity[] bpelEntities) {
58: BpelEntity bpelEntity = bpelEntities[0];
59: BPELElementsBuilder builder = bpelEntity.getBpelModel()
60: .getBuilder();
61: For newFor = builder.createFor();
62: try {
63: newFor.setContent(DEFAULT_FOR_VALUE);
64: } catch (VetoException ex) {
65: ErrorManager.getDefault().notify(
66: ErrorManager.INFORMATIONAL, ex);
67: }
68:
69: if (bpelEntity instanceof Pick) {
70: OnAlarmPick newOnAlarmPick = builder.createOnAlarmPick();
71: newOnAlarmPick.setTimeEvent(newFor);
72:
73: ((Pick) bpelEntity).addOnAlarm(newOnAlarmPick);
74: } else if (bpelEntity instanceof EventHandlers) {
75: OnAlarmEvent newOnAlarmEvent = builder.createOnAlarmEvent();
76: newOnAlarmEvent.setTimeEvent(newFor);
77: ((EventHandlers) bpelEntity).addOnAlarm(newOnAlarmEvent);
78: }
79: }
80:
81: protected boolean enable(BpelEntity[] bpelEntities) {
82: if (!super .enable(bpelEntities)) {
83: return false;
84: }
85:
86: BpelEntity bpelEntity = bpelEntities[0];
87:
88: return (bpelEntity instanceof Pick)
89: || (bpelEntity instanceof EventHandlers);
90: }
91: }
|