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: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.etl.ui.view.graph.actions;
042:
043: import java.awt.event.ActionEvent;
044: import java.awt.event.InputEvent;
045: import java.net.URL;
046: import java.util.List;
047:
048: import javax.swing.Action;
049: import javax.swing.ImageIcon;
050: import javax.swing.KeyStroke;
051:
052: import org.netbeans.modules.etl.ui.DataObjectProvider;
053: import org.netbeans.modules.etl.ui.model.impl.ETLCollaborationModel;
054: import org.netbeans.modules.etl.ui.view.ETLCollaborationTopPanel;
055: import org.netbeans.modules.sql.framework.model.SQLJoinView;
056: import org.netbeans.modules.sql.framework.ui.graph.actions.GraphAction;
057: import org.netbeans.modules.sql.framework.ui.view.join.JoinMainDialog;
058: import org.netbeans.modules.sql.framework.ui.view.join.JoinUtility;
059: import org.openide.DialogDisplayer;
060: import org.openide.NotifyDescriptor;
061: import net.java.hulp.i18n.Logger;
062: import com.sun.sql.framework.exception.BaseException;
063: import org.netbeans.modules.etl.logger.Localizer;
064: import org.netbeans.modules.etl.logger.LogUtil;
065: import org.netbeans.modules.sql.framework.model.DBTable;
066:
067: /**
068: * This action is to create or edit join
069: *
070: * @author Ritesh Adval
071: * @version $Revision$
072: */
073: public class JoinAction extends GraphAction {
074:
075: private static final URL joinImgUrl = ValidationAction.class
076: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/join_view.png");
077: private static final String LOG_CATEGORY = JoinAction.class
078: .getName();
079: private static transient final Logger mLogger = LogUtil
080: .getLogger(JoinAction.class.getName());
081: private static transient final Localizer mLoc = Localizer.get();
082:
083: public JoinAction() {
084: // action name
085: String nbBundle1 = mLoc.t("PRSR001: Create New Join...");
086: this .putValue(Action.NAME, Localizer.parse(nbBundle1));
087:
088: // action icon
089: this .putValue(Action.SMALL_ICON, new ImageIcon(joinImgUrl));
090:
091: // action tooltip
092: String nbBundle2 = mLoc.t("PRSR001: Create New Join (Cntl-J)");
093: this .putValue(Action.SHORT_DESCRIPTION, Localizer
094: .parse(nbBundle2));
095:
096: // Acceleratot Cntl-J
097: this .putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
098: 'J', InputEvent.CTRL_MASK));
099: }
100:
101: /**
102: * called when this action is performed in the ui
103: *
104: * @param ev event
105: */
106: public void actionPerformed(ActionEvent ev) {
107: ETLCollaborationTopPanel etlEditor = null;
108: try {
109: etlEditor = DataObjectProvider.getProvider()
110: .getActiveDataObject().getETLEditorTopPanel();
111: } catch (Exception ex) {
112: //ignore
113: }
114:
115: // first check if user has selected some tables/join view and he wants to create
116: // a join
117:
118: // if user just selects one join view then he wants to edit that
119: // if there is no selection then user wants to create a new join
120: ETLCollaborationModel collabModel = DataObjectProvider
121: .getProvider().getActiveDataObject().getModel();
122:
123: if (collabModel != null) {
124: List<DBTable> sList = collabModel.getSQLDefinition()
125: .getJoinSources();
126: JoinMainDialog.showJoinDialog(sList, null, etlEditor
127: .getGraphView(), true);
128:
129: if (JoinMainDialog.getClosingButtonState() == JoinMainDialog.OK_BUTTON) {
130: SQLJoinView joinView = JoinMainDialog.getSQLJoinView();
131: try {
132: if (joinView != null) {
133: JoinUtility.handleNewJoinCreation(joinView,
134: JoinMainDialog.getTableColumnNodes(),
135: etlEditor.getGraphView());
136: }
137: } catch (BaseException ex) {
138: DialogDisplayer
139: .getDefault()
140: .notify(
141: new NotifyDescriptor.Message(
142: "Error adding join view.",
143: NotifyDescriptor.INFORMATION_MESSAGE));
144: mLogger.errorNoloc(mLoc.t(
145: "PRSR025: error adding join view{0}",
146: LOG_CATEGORY), ex);
147: }
148: }
149: }
150: }
151: }
|