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.sql.framework.ui.view.graph;
042:
043: import com.sun.sql.framework.exception.BaseException;
044: import com.sun.sql.framework.exception.DBSQLException;
045: import java.awt.Color;
046: import java.awt.event.ActionEvent;
047: import java.awt.event.ActionListener;
048: import java.net.URL;
049:
050: import javax.swing.Icon;
051: import javax.swing.ImageIcon;
052: import javax.swing.JMenuItem;
053:
054: import org.netbeans.modules.sql.framework.model.SQLCondition;
055: import org.netbeans.modules.sql.framework.model.SQLObject;
056: import org.netbeans.modules.sql.framework.model.TargetTable;
057: import org.netbeans.modules.sql.framework.ui.graph.ICommand;
058: import org.netbeans.modules.sql.framework.ui.graph.impl.GradientBrush;
059: import org.openide.util.Exceptions;
060:
061: import com.nwoods.jgo.JGoBrush;
062: import java.awt.event.InputEvent;
063: import javax.swing.JOptionPane;
064: import javax.swing.KeyStroke;
065: import net.java.hulp.i18n.Logger;
066: import org.netbeans.modules.etl.logger.Localizer;
067: import org.netbeans.modules.etl.logger.LogUtil;
068: import org.netbeans.modules.sql.framework.model.DBMetaDataFactory;
069: import org.netbeans.modules.sql.framework.model.SQLDBModel;
070: import org.netbeans.modules.sql.framework.model.SQLDBTable;
071: import org.netbeans.modules.sql.framework.model.impl.SQLDBModelImpl;
072: import org.netbeans.modules.sql.framework.model.utils.SQLObjectUtil;
073: import org.netbeans.modules.sql.framework.model.visitors.SQLDBSynchronizationVisitor;
074: import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
075: import org.netbeans.modules.sql.framework.ui.model.CollabSQLUIModel;
076: import org.netbeans.modules.sql.framework.ui.view.BasicTopView;
077: import org.openide.awt.StatusDisplayer;
078: import org.openide.windows.WindowManager;
079:
080: /**
081: * @author Ritesh Adval
082: */
083: public class SQLTargetTableArea extends SQLBasicTableArea {
084:
085: private static URL targetTableImgUrl = SQLTargetTableArea.class
086: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/TargetTable.png");
087: private static URL showDataUrl = SQLSourceTableArea.class
088: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/SourceTable.png");
089: private static URL showSqlUrl = SQLSourceTableArea.class
090: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/Show_Sql.png");
091: private static URL propertiesUrl = SQLSourceTableArea.class
092: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/properties.png");
093: private static URL showRejectionDataImgUrl = SQLBasicTableArea.class
094: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/showRejectedData.png");
095: private static URL synchroniseImgUrl = SQLSourceTableArea.class
096: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/refresh.png");
097: private static URL targetTableConditionImgUrl = SQLBasicTableArea.class
098: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/targetTableCondition.png");
099: private static URL dataFilterImgUrl = SQLSourceTableArea.class
100: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/filter16.gif");
101: private static URL remountImgUrl = SQLTargetTableArea.class
102: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/redo.png");
103: private static final Color DEFAULT_BG_COLOR = new Color(219, 207,
104: 219);//(204, 213, 241);
105: private static final Color DEFAULT_BG_COLOR_DARK = new Color(221,
106: 235, 246);//(165, 193, 249);
107: private static final JGoBrush DEFAULT_TITLE_BRUSH = new GradientBrush(
108: DEFAULT_BG_COLOR, DEFAULT_BG_COLOR_DARK);
109: private JMenuItem showSqlItem;
110: private JMenuItem showDataItem;
111: private JMenuItem showRejectionDataItem;
112: private JMenuItem editJoinConditionItem;
113: private JMenuItem editFilterConditionItem;
114: private JMenuItem propertiesItem;
115: private JMenuItem synchroniseItem;
116: private JMenuItem remountItem;
117: private static transient final Logger mLogger = LogUtil
118: .getLogger(SQLTargetTableArea.class.getName());
119: private static transient final Localizer mLoc = Localizer.get();
120:
121: /**
122: * Creates a new instance of SQLTargetTableArea
123: */
124: public SQLTargetTableArea() {
125: super ();
126: }
127:
128: /**
129: * Creates a new instance of SQLTargetTableArea
130: *
131: * @param tgttable
132: *
133: */
134: public SQLTargetTableArea(TargetTable tgttable) {
135: super ();
136: }
137:
138: /**
139: * @see org.netbeans.modules.sql.framework.ui.view.graph.SQLBasicTableArea#initializePopUpMenu()
140: */
141: protected void initializePopUpMenu() {
142: try {
143: ActionListener aListener = new TableActionListener();
144: // Show SQL
145: String nbBundle1 = mLoc.t("PRSR001: Show SQL");
146: String lblShowSql = Localizer.parse(nbBundle1);
147: showSqlItem = new JMenuItem(lblShowSql, new ImageIcon(
148: showSqlUrl));
149: showSqlItem.setAccelerator(KeyStroke.getKeyStroke('S',
150: InputEvent.CTRL_MASK));
151: showSqlItem.addActionListener(aListener);
152: popUpMenu.add(showSqlItem);
153:
154: // Show data
155: String nbBundle2 = mLoc.t("PRSR001: Show Data");
156: String lblShowData = Localizer.parse(nbBundle2);
157: showDataItem = new JMenuItem(lblShowData, new ImageIcon(
158: showDataUrl));
159: showDataItem.setAccelerator(KeyStroke.getKeyStroke('D',
160: InputEvent.CTRL_MASK));
161: showDataItem.addActionListener(aListener);
162: popUpMenu.add(showDataItem);
163:
164: // Show rejection data
165: // TODO: Add listener framework to enable/disable this action depending on whether
166: // a validation condition exists
167: String nbBundle3 = mLoc.t("PRSR001: Show Rejected Data...");
168: String lblRjtShowData = Localizer.parse(nbBundle3);
169: showRejectionDataItem = new JMenuItem(lblRjtShowData,
170: new ImageIcon(showRejectionDataImgUrl));
171: showRejectionDataItem.setAccelerator(KeyStroke
172: .getKeyStroke('E', InputEvent.CTRL_MASK));
173: showRejectionDataItem.addActionListener(aListener);
174: popUpMenu.add(showRejectionDataItem);
175:
176: addSelectVisibleColumnsPopUpMenu(aListener);
177: String nbBundle4 = mLoc.t("PRSR001: Refresh Metadata");
178: synchroniseItem = new JMenuItem(Localizer.parse(nbBundle4),
179: new ImageIcon(synchroniseImgUrl));
180: synchroniseItem.setAccelerator(KeyStroke.getKeyStroke('R',
181: InputEvent.CTRL_MASK));
182: synchroniseItem.addActionListener(aListener);
183: popUpMenu.add(synchroniseItem);
184:
185: String nbBundle5 = mLoc.t("PRSR001: Remount");
186: String lblRemount = Localizer.parse(nbBundle5);
187: remountItem = new JMenuItem(lblRemount, new ImageIcon(
188: remountImgUrl));
189: remountItem.setAccelerator(KeyStroke.getKeyStroke('M',
190: InputEvent.CTRL_MASK));
191: remountItem.addActionListener(aListener);
192: SQLObject tbl = (SQLObject) SQLTargetTableArea.this
193: .getDataObject();
194: SQLDBModelImpl impl = (SQLDBModelImpl) tbl
195: .getParentObject();
196: if (impl.getETLDBConnectionDefinition().getDBType().equals(
197: DBMetaDataFactory.AXION)
198: || impl.getETLDBConnectionDefinition().getDBType()
199: .equalsIgnoreCase("Internal")) {
200: popUpMenu.add(remountItem);
201: }
202: popUpMenu.addSeparator();
203:
204: // TODO: show join condition only if source table exist (Delete, Static Insert/Update does not require Join Condition)
205: // Target Join Condition
206: String nbBundle6 = mLoc
207: .t("PRSR001: Target Join Condition...");
208: String lblTargetCondition = Localizer.parse(nbBundle6);
209: editJoinConditionItem = new JMenuItem(lblTargetCondition,
210: new ImageIcon(targetTableConditionImgUrl));
211: editJoinConditionItem.setAccelerator(KeyStroke
212: .getKeyStroke('J', InputEvent.CTRL_MASK));
213: editJoinConditionItem.addActionListener(aListener);
214: popUpMenu.add(editJoinConditionItem);
215:
216: // Target Filter Condition
217: String nbBundle7 = mLoc
218: .t("PRSR001: Outer Filter Condition...");
219: String lblTargetFilterCondition = Localizer
220: .parse(nbBundle7);
221: editFilterConditionItem = new JMenuItem(
222: lblTargetFilterCondition, new ImageIcon(
223: dataFilterImgUrl));
224: editFilterConditionItem.setAccelerator(KeyStroke
225: .getKeyStroke('F', InputEvent.CTRL_MASK));
226: editFilterConditionItem.addActionListener(aListener);
227: popUpMenu.add(editFilterConditionItem);
228: popUpMenu.addSeparator();
229:
230: // Remove
231: addRemovePopUpMenu(aListener);
232:
233: // Properties
234: popUpMenu.addSeparator();
235: String nbBundle8 = mLoc.t("PRSR001: Properties");
236: String lblProps = Localizer.parse(nbBundle8);
237: propertiesItem = new JMenuItem(lblProps, new ImageIcon(
238: propertiesUrl));
239: propertiesItem.setAccelerator(KeyStroke.getKeyStroke('P',
240: InputEvent.CTRL_MASK));
241: propertiesItem.addActionListener(aListener);
242: popUpMenu.add(propertiesItem);
243: } catch (BaseException ex) {
244: Exceptions.printStackTrace(ex);
245: }
246: }
247:
248: Icon createIcon() {
249: return new ImageIcon(targetTableImgUrl);
250: }
251:
252: private class TableActionListener implements ActionListener {
253:
254: /**
255: * Invoked when an action occurs.
256: *
257: * @param e ActionEvent to handle
258: */
259: public void actionPerformed(ActionEvent e) {
260: Object source = e.getSource();
261: if (source == propertiesItem) {
262: Properties_ActionPerformed(e);
263: } else if (source == showSqlItem) {
264: ShowSql_ActionPerformed(e);
265: } else if (source == remountItem) {
266: Remount_ActionPerformed(e);
267: } else if (source == showDataItem) {
268: ShowData_ActionPerformed(e);
269: } else if (source == showRejectionDataItem) {
270: ShowRejectionData_ActionPerformed(e);
271: } else if (source == editJoinConditionItem) {
272: ShowTargetJoinCondition_ActionPerformed(e);
273: } else if (source == editFilterConditionItem) {
274: ShowTargetFilterCondition_ActionPerformed(e);
275: } else if (source == synchroniseItem) {
276: synchroniseItem_ActionPerformed(e);
277: } else {
278: handleCommonActions(e);
279: }
280: }
281: }
282:
283: private void Properties_ActionPerformed(ActionEvent e) {
284: if (!WindowManager.getDefault().findTopComponent("properties")
285: .isShowing()) {
286: WindowManager.getDefault().findTopComponent("properties")
287: .open();
288: }
289: }
290:
291: private void ShowSql_ActionPerformed(ActionEvent e) {
292: SQLObject sqlObject = (SQLObject) SQLTargetTableArea.this
293: .getDataObject();
294: Object[] args = new Object[] { sqlObject };
295: this .getGraphView().execute(ICommand.SHOW_SQL_CMD, args);
296: }
297:
298: private void Remount_ActionPerformed(ActionEvent e) {
299: try {
300: SQLObject sqlObject = (SQLObject) SQLTargetTableArea.this
301: .getDataObject();
302: SQLObjectUtil.dropTable(table, (SQLDBModel) table
303: .getParent());
304: SQLObjectUtil.createTable(table, (SQLDBModel) table
305: .getParent());
306: SQLObjectUtil.setOrgProperties(table);
307: } catch (Exception ex) {
308: Exceptions.printStackTrace(ex);
309: StatusDisplayer.getDefault().setStatusText(
310: "Unable to remount :" + ex.getMessage());
311: }
312: }
313:
314: private void ShowData_ActionPerformed(ActionEvent e) {
315: SQLObject tbl = (SQLObject) SQLTargetTableArea.this
316: .getDataObject();
317: this .getGraphView().execute(ICommand.SHOW_DATA_CMD,
318: new Object[] { tbl });
319: }
320:
321: private void ShowRejectionData_ActionPerformed(ActionEvent e) {
322: SQLObject tbl = (SQLObject) SQLTargetTableArea.this
323: .getDataObject();
324: this .getGraphView().execute(ICommand.SHOW_REJECTION_DATA_CMD,
325: new Object[] { tbl });
326: }
327:
328: private void ShowTargetJoinCondition_ActionPerformed(ActionEvent e) {
329: SQLObject sqlObject = (SQLObject) SQLTargetTableArea.this
330: .getDataObject();
331: Object[] args = new Object[] { SQLTargetTableArea.this ,
332: sqlObject };
333: this .getGraphView().execute(
334: ICommand.SHOW_TARGET_JOIN_CONDITION_CMD, args);
335: }
336:
337: private void ShowTargetFilterCondition_ActionPerformed(ActionEvent e) {
338: SQLObject sqlObject = (SQLObject) SQLTargetTableArea.this
339: .getDataObject();
340: Object[] args = new Object[] { SQLTargetTableArea.this ,
341: sqlObject };
342: this .getGraphView().execute(
343: ICommand.SHOW_TARGET_FILTER_CONDITION_CMD, args);
344: }
345:
346: private void synchroniseItem_ActionPerformed(ActionEvent e) {
347: IGraphView gView = this .getGraphView();
348:
349: String nbBundle9 = mLoc
350: .t("PRSR001: If columns are deleted or renamed you may lose existing mappings.");
351: String dlgMsg = Localizer.parse(nbBundle9);
352: String nbBundle10 = mLoc.t("PRSR001: Refresh Metadata");
353: String dlgTitle = Localizer.parse(nbBundle10);
354: int response = JOptionPane.showConfirmDialog(WindowManager
355: .getDefault().getMainWindow(), dlgMsg, dlgTitle,
356: JOptionPane.OK_CANCEL_OPTION,
357: JOptionPane.WARNING_MESSAGE);
358:
359: if (JOptionPane.OK_OPTION == response) {
360: try {
361:
362: SQLDBTable tbl = (SQLDBTable) SQLTargetTableArea.this
363: .getDataObject();
364: SQLDBSynchronizationVisitor visitView = new SQLDBSynchronizationVisitor();
365:
366: SQLTableArea tableArea1 = (SQLTableArea) this
367: .getTableArea();
368: MetaTableModel model = (MetaTableModel) tableArea1
369: .getModel();
370: visitView.mergeCollabTableWithDatabaseTable(tbl, model);
371: if (!visitView.infoList.isEmpty()) {
372: tableArea1.layoutChildren();
373: tableArea1.setHeight(tableArea1.getMaximumHeight());
374: // Mark collab as needing to be persisted.
375: Object graphModel = getGraphView().getGraphModel();
376: if (graphModel instanceof CollabSQLUIModel) {
377: ((CollabSQLUIModel) graphModel).setDirty(true);
378: }
379: }
380: BasicTopView gvMgr = (BasicTopView) gView
381: .getGraphViewContainer();
382: gvMgr.showRefreshMetadataInfo(visitView.infoList);
383: } catch (DBSQLException ex) {
384: Exceptions.printStackTrace(ex);
385: } catch (Exception ex) {
386: Exceptions.printStackTrace(ex);
387: }
388: }
389: }
390:
391: /**
392: * Sets the data object
393: *
394: * @param obj - then object to be represented by this node
395: */
396: public void setDataObject(Object obj) {
397: super .setDataObject(obj);
398: setConditionIcons();
399: }
400:
401: public void setConditionIcons() {
402: TargetTable tbl = (TargetTable) this .getDataObject();
403: if (tbl != null) {
404: SQLCondition c1 = tbl.getJoinCondition();
405: setTableConditionIcons(c1);
406:
407: SQLCondition c2 = tbl.getFilterCondition();
408: setTableConditionIcons(c2);
409: }
410: }
411:
412: /**
413: * @return
414: * @see org.netbeans.modules.sql.framework.ui.view.graph.SQLBasicTableArea#getDefaultTitleBrush()
415: */
416: protected JGoBrush getDefaultTitleBrush() {
417: return DEFAULT_TITLE_BRUSH;
418: }
419:
420: /**
421: * @return
422: * @see org.netbeans.modules.sql.framework.ui.view.graph.SQLBasicTableArea#getDefaultBackgroundColor()
423: */
424: protected Color getDefaultBackgroundColor() {
425: return DEFAULT_BG_COLOR;
426: }
427: }
|