001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028:
029: package org.netbeans.modules.compapp.casaeditor.graph.actions;
030:
031: import java.awt.Dialog;
032: import java.awt.event.MouseEvent;
033: import javax.swing.SwingUtilities;
034: import org.netbeans.api.visual.action.WidgetAction;
035: import org.netbeans.api.visual.widget.ImageWidget;
036: import org.netbeans.api.visual.widget.Widget;
037: import org.netbeans.modules.compapp.casaeditor.Constants;
038: import org.netbeans.modules.compapp.casaeditor.design.CasaModelGraphScene;
039: import org.netbeans.modules.compapp.casaeditor.graph.CasaNodeWidget;
040: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaComponent;
041: import org.openide.DialogDescriptor;
042: import org.openide.DialogDisplayer;
043: import org.openide.explorer.propertysheet.PropertySheet;
044: import org.openide.nodes.Node;
045: import org.openide.util.NbBundle;
046:
047: /**
048: *
049: * @author rdara
050: */
051: public final class EditablePropertiesAction extends
052: WidgetAction.Adapter {
053:
054: private Node mEditNode;
055:
056: public EditablePropertiesAction() {
057: }
058:
059: public State mousePressed(Widget widget, WidgetMouseEvent event) {
060: mEditNode = null;
061:
062: if (event.getButton() != MouseEvent.BUTTON1) {
063: return State.REJECTED;
064: }
065: if (!(widget instanceof ImageWidget)) {
066: return State.REJECTED;
067: }
068: ((ImageWidget) widget).setPaintAsDisabled(true);
069: while (widget instanceof CasaNodeWidget) {
070: widget = widget.getParentWidget();
071: }
072: CasaModelGraphScene scene = (CasaModelGraphScene) widget
073: .getScene();
074: CasaComponent casaComponent = (CasaComponent) scene
075: .findObject(widget);
076: if (casaComponent == null) {
077: return State.REJECTED;
078: }
079: mEditNode = scene.getNodeFactory().createNodeFor(casaComponent);
080: if (mEditNode == null) {
081: return State.REJECTED;
082: }
083: return State.CONSUMED;
084: }
085:
086: public State mouseReleased(Widget widget, WidgetMouseEvent event) {
087: if (mEditNode == null) {
088: return State.REJECTED;
089: }
090: if (widget instanceof ImageWidget) {
091: ((ImageWidget) widget).setPaintAsDisabled(false);
092: }
093: final PropertySheet propertySheetPanel = new PropertySheet();
094: final Node editNodeRef = mEditNode;
095: mEditNode = null;
096:
097: propertySheetPanel.setNodes(new Node[] { editNodeRef });
098: final Object[] options = new Object[] { Constants.CLOSE };
099: final DialogDescriptor descriptor = new DialogDescriptor(
100: propertySheetPanel,
101: NbBundle.getMessage(getClass(), "STR_PROPERTIES",
102: editNodeRef.getDisplayName()), true, options,
103: null, DialogDescriptor.DEFAULT_ALIGN, null, null);
104: descriptor.setClosingOptions(options);
105:
106: final Dialog dlg = DialogDisplayer.getDefault().createDialog(
107: descriptor);
108:
109: // The dialog is modal, allow the action chain to continue while
110: // we open the dialog later.
111: SwingUtilities.invokeLater(new Runnable() {
112: public void run() {
113: dlg.setVisible(true);
114: }
115: });
116:
117: return State.CONSUMED;
118: }
119:
120: // If the mouse is ever moved off of the widget, either from a drag/move, then
121: // we must lock the state so that we get the mouseReleased event.
122: public WidgetAction.State dragExit(Widget widget,
123: WidgetAction.WidgetMouseEvent event) {
124: if (mEditNode == null) {
125: return State.REJECTED;
126: }
127: return State.createLocked(widget, this );
128: }
129:
130: // If the mouse is ever moved off of the widget, either from a drag/move, then
131: // we must lock the state so that we get the mouseReleased event.
132: public WidgetAction.State mouseExited(Widget widget,
133: WidgetAction.WidgetMouseEvent event) {
134: if (mEditNode == null) {
135: return State.REJECTED;
136: }
137: return State.createLocked(widget, this );
138: }
139:
140: // If the mouse is ever moved off of the widget, either from a drag/move, then
141: // we must lock the state so that we get the mouseReleased event.
142: public WidgetAction.State mouseDragged(Widget widget,
143: WidgetAction.WidgetMouseEvent event) {
144: if (mEditNode == null) {
145: return State.REJECTED;
146: }
147: return State.createLocked(widget, this );
148: }
149:
150: protected boolean isLocked() {
151: return mEditNode != null;
152: }
153:
154: }
|