001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.xslt.mapper.xpatheditor;
021:
022: import java.awt.Dialog;
023: import java.awt.Window;
024: import org.netbeans.modules.soa.mapper.common.basicmapper.IBasicMapper;
025: import org.netbeans.modules.soa.mapper.common.basicmapper.IBasicMapperLiteralUpdateEventInfo;
026: import org.netbeans.modules.soa.mapper.common.basicmapper.literal.ILiteralEditor;
027: import org.netbeans.modules.soa.mapper.common.basicmapper.literal.ILiteralUpdater;
028: import org.netbeans.modules.soa.mapper.common.basicmapper.methoid.IFieldNode;
029: import org.netbeans.modules.soa.mapper.common.basicmapper.methoid.IMethoid;
030: import org.netbeans.modules.soa.mapper.common.basicmapper.methoid.IMethoidNode;
031: import org.netbeans.modules.soa.ui.form.valid.DefaultDialogDescriptor;
032: import org.netbeans.modules.soa.ui.form.valid.SoaDialogDisplayer;
033: import org.openide.DialogDescriptor;
034: import org.openide.util.HelpCtx;
035: import org.openide.util.NbBundle;
036:
037: /**
038: * Implements special case of a XPath expression string literal editor.
039: *
040: * @author nk160297
041: */
042: public class XPathLiteralEditor implements ILiteralEditor {
043:
044: private Window mOwner;
045:
046: private IBasicMapper mBasicMapper;
047:
048: private IFieldNode mFieldNode;
049:
050: private ILiteralUpdater mUpdateListener;
051:
052: private IMethoidNode mMethoidNode;
053:
054: private IMethoid mMethoid;
055:
056: /**
057: * Creates a new instance of XPathLiteralEditor
058: */
059: public XPathLiteralEditor(Window owner, IBasicMapper basicMapper,
060: IFieldNode fieldNode, ILiteralUpdater updateListener) {
061: super ();
062: mOwner = owner;
063: mBasicMapper = basicMapper;
064: mFieldNode = fieldNode;
065: mUpdateListener = updateListener;
066: mMethoidNode = (IMethoidNode) mFieldNode.getGroupNode();
067: mMethoid = (IMethoid) mMethoidNode.getMethoidObject();
068: }
069:
070: /**
071: * @see org.netbeans.modules.soa.mapper.common.basicmapper.literal
072: * * .ILiteralEditor#show()
073: */
074: public void show() {
075: ExpressionEditor exprEditor = new ExpressionEditor(mBasicMapper);
076: exprEditor.getAccessibleContext().setAccessibleDescription(
077: NbBundle.getMessage(ExpressionEditor.class,
078: "ACSD_LBL_XPath_ExpressionBuilder")); // NOI18N
079: String expr = mFieldNode.getLiteralName();
080: if (expr != null && expr.length() > 0) {
081: exprEditor.setSelectedValue(expr);
082: }
083: //
084: String title = NbBundle.getMessage(ExpressionEditor.class,
085: "TITLE_ExpressionBuilder");
086: DefaultDialogDescriptor descriptor = new DefaultDialogDescriptor(
087: exprEditor, title);
088: descriptor.setHelpCtx(new HelpCtx("xslt_editor_xpath")); // NOI18N
089:
090: Dialog dialog = SoaDialogDisplayer.getDefault().createDialog(
091: descriptor);
092: dialog.setVisible(true);
093: //
094: if (!descriptor.isOkHasPressed()) {
095: return;
096: }
097: String literal = exprEditor.getSelectedValue();
098: if (null == literal) {
099: literal = "";
100: }
101: fireLiteralUpdated(literal);
102: }
103:
104: /**
105: * @see org.netbeans.modules.soa.mapper.common.basicmapper.literal
106: * * .ILiteralEditor#getUpdateListener()
107: */
108: public ILiteralUpdater getUpdateListener() {
109: return mUpdateListener;
110: }
111:
112: /**
113: * Fires an event for the update of the duration literal.
114: * * @param newValue New value for the duration literal.
115: */
116: private void fireLiteralUpdated(final String newValue) {
117: // set the expression
118: mBasicMapper
119: .updateFieldLiteral(new IBasicMapperLiteralUpdateEventInfo() {
120: /**
121: * @see org.netbeans.modules.soa.mapper.common.basicmapper
122: * * .IBasicMapperLiteralUpdateEventInfo#getLiteralUpdater()
123: */
124: public ILiteralUpdater getLiteralUpdater() {
125: return mUpdateListener;
126: }
127:
128: /**
129: * @see org.netbeans.modules.soa.mapper.common.basicmapper
130: * * .IBasicMapperLiteralUpdateEventInfo#getMethoidNode()
131: */
132: public IMethoidNode getMethoidNode() {
133: return mMethoidNode;
134: }
135:
136: /**
137: * @see org.netbeans.modules.soa.mapper.common.basicmapper
138: * * .IBasicMapperLiteralUpdateEventInfo#getFieldNode()
139: */
140: public IFieldNode getFieldNode() {
141: return mFieldNode;
142: }
143:
144: /**
145: * @see org.netbeans.modules.soa.mapper.common.basicmapper
146: * * .IBasicMapperLiteralUpdateEventInfo#getNewValue()
147: */
148: public String getNewValue() {
149: return newValue;
150: }
151:
152: /**
153: * @see org.netbeans.modules.soa.mapper.common.basicmapper
154: * * .IBasicMapperLiteralUpdateEventInfo#isLiteralMethoid()
155: */
156: public boolean isLiteralMethoid() {
157: return mMethoid.isLiteral();
158: }
159: });
160: }
161: }
|