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.model.nodes.actions;
021:
022: import java.awt.Dialog;
023: import java.awt.event.ActionEvent;
024: import org.netbeans.modules.soa.ui.form.valid.DefaultDialogDescriptor;
025: import org.netbeans.modules.soa.ui.form.valid.SoaDialogDisplayer;
026: import org.netbeans.modules.xml.xpath.AbstractXPathModelHelper;
027: import org.netbeans.modules.xml.xpath.XPathException;
028: import org.netbeans.modules.xml.xpath.XPathExpression;
029: import org.netbeans.modules.xml.xpath.XPathModel;
030: import org.netbeans.modules.xml.xpath.XPathPredicateExpression;
031: import org.netbeans.modules.xslt.mapper.model.targettree.SchemaNode;
032: import org.netbeans.modules.xslt.mapper.view.PredicateManager;
033: import org.netbeans.modules.xslt.mapper.view.XsltMapper;
034: import org.netbeans.modules.xslt.mapper.xpatheditor.ExpressionEditor;
035: import org.openide.util.HelpCtx;
036: import org.openide.util.NbBundle;
037:
038: /**
039: * Shows the Expression editor dialog in order to create a new predicate.
040: *
041: * @author nk160297
042: */
043: public class AddPredicateAction extends XsltNodeAction {
044:
045: private static final long serialVersionUID = 1L;
046:
047: public AddPredicateAction(XsltMapper xsltMapper, SchemaNode node) {
048: super (xsltMapper, node);
049: postInit();
050: // putValue(DeleteAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0));
051: }
052:
053: public String getDisplayName() {
054: return NbBundle.getMessage(ActionConst.class, "ADD_PREDICATE"); // NOI18N
055: }
056:
057: public void actionPerformed(ActionEvent e) {
058: // XslModel model = myXsltMapper.getContext().getXSLModel();
059: // Object dataObject = myTreeNode.getDataObject();
060:
061: ExpressionEditor exprEditor = new ExpressionEditor(myXsltMapper);
062: //
063: // String expr = mFieldNode.getLiteralName();
064: // if (expr != null && expr.length() > 0) {
065: // exprEditor.setSelectedValue(expr);
066: // }
067: //
068: String title = NbBundle.getMessage(ExpressionEditor.class,
069: "TITLE_ExpressionBuilder");
070: DefaultDialogDescriptor descriptor = new DefaultDialogDescriptor(
071: exprEditor, title);
072: descriptor.setHelpCtx(new HelpCtx("xslt_editor_xpath")); // NOI18N
073:
074: Dialog dialog = SoaDialogDisplayer.getDefault().createDialog(
075: descriptor);
076: dialog.setVisible(true);
077: //
078: if (!descriptor.isOkHasPressed()) {
079: return;
080: }
081: String literal = exprEditor.getSelectedValue();
082: if (null == literal) {
083: literal = "";
084: }
085: //
086: XPathModel xpImpl = AbstractXPathModelHelper.getInstance()
087: .newXPathModel();
088: try {
089: XPathExpression expression = xpImpl
090: .parseExpression(literal);
091: XPathPredicateExpression predicate = AbstractXPathModelHelper
092: .getInstance().newXPathPredicateExpression(
093: expression);
094: //
095: XPathPredicateExpression[] predArr = new XPathPredicateExpression[] { predicate };
096:
097: PredicateManager pm = myXsltMapper.getPredicateManager();
098: pm.createPredicatedNode(myTreeNode, predArr);
099: } catch (XPathException ex) {
100: // Error.Incorrect expression
101: }
102: ;
103:
104: }
105:
106: }
|