001: /*
002: *
003: * Copyright (c) 2003-2005, SeeBeyond Technology Corporation,
004: * All Rights Reserved
005: *
006: * This program, and all the routines referenced herein,
007: * are the proprietary properties and trade secrets of
008: * SEEBEYOND TECHNOLOGY CORPORATION.
009: *
010: * Except as provided for by license agreement, this
011: * program shall not be duplicated, used, or disclosed
012: * without written consent signed by an officer of
013: * SEEBEYOND TECHNOLOGY CORPORATION.
014: *
015: */
016:
017: package org.netbeans.modules.etl.ui.view.graph.actions;
018:
019: import com.sun.sql.framework.exception.DBSQLException;
020: import org.netbeans.modules.sql.framework.model.SQLDBTable;
021: import org.netbeans.modules.sql.framework.model.SourceTable;
022: import org.netbeans.modules.sql.framework.model.TargetTable;
023: import org.netbeans.modules.sql.framework.model.visitors.SQLDBSynchronizationVisitor;
024: import java.awt.event.ActionEvent;
025: import java.awt.event.InputEvent;
026: import java.net.URL;
027: import java.util.ArrayList;
028: import javax.swing.Action;
029: import java.util.Iterator;
030: import java.util.List;
031: import javax.swing.ImageIcon;
032: import javax.swing.JOptionPane;
033: import javax.swing.KeyStroke;
034: import net.java.hulp.i18n.Logger;
035: import org.netbeans.modules.etl.logger.Localizer;
036: import org.netbeans.modules.etl.logger.LogUtil;
037: import org.netbeans.modules.etl.ui.DataObjectProvider;
038: import org.netbeans.modules.sql.framework.model.SQLJoinView;
039: import org.openide.util.Exceptions;
040: import org.netbeans.modules.sql.framework.ui.view.graph.MetaTableModel;
041: import org.netbeans.modules.sql.framework.ui.view.graph.SQLTableArea;
042: import org.netbeans.modules.sql.framework.model.visitors.SQLDBSynchronizationVisitor;
043: import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
044: import org.netbeans.modules.sql.framework.ui.model.CollabSQLUIModel;
045: import org.netbeans.modules.sql.framework.ui.view.graph.SQLSourceTableArea;
046: import org.netbeans.modules.sql.framework.ui.view.graph.SQLTargetTableArea;
047: import org.netbeans.modules.sql.framework.ui.graph.actions.GraphAction;
048: import org.netbeans.modules.sql.framework.ui.view.BasicTopView;
049: import org.netbeans.modules.sql.framework.ui.view.join.JoinViewGraphNode;
050: import org.openide.windows.WindowManager;
051:
052: /**
053: * @author Nithya Radhakrishnan
054: * @version $Revision$
055: */
056: public class RefreshMetadataAction extends GraphAction {
057:
058: private static final URL synchroniseImgUrl = RefreshMetadataAction.class
059: .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/refresh.png");
060: private static transient final Logger mLogger = LogUtil
061: .getLogger(RefreshMetadataAction.class.getName());
062: private static transient final Localizer mLoc = Localizer.get();
063:
064: public RefreshMetadataAction() {
065: //action name
066: String nbBundle1 = mLoc.t("PRSR001: Refresh Metadata");
067: this .putValue(Action.NAME, Localizer.parse(nbBundle1));
068:
069: //action icon
070: this .putValue(Action.SMALL_ICON, new ImageIcon(
071: synchroniseImgUrl));
072:
073: //action tooltip
074: String nbBundle2 = mLoc.t("PRSR001: Refresh Metadata (Cntl-R)");
075: this .putValue(Action.SHORT_DESCRIPTION, Localizer
076: .parse(nbBundle2));
077: // Acceleratot Cntl-R
078: this .putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
079: 'R', InputEvent.CTRL_MASK));
080: }
081:
082: /**
083: * called when this action is performed in the ui
084: *
085: * @param ev event
086: */
087: public void actionPerformed(ActionEvent ev) {
088: IGraphView graphView = (IGraphView) ev.getSource();
089: CollabSQLUIModel model = (CollabSQLUIModel) graphView
090: .getGraphModel();
091: List infoList = new ArrayList();
092: String nbBundle3 = mLoc
093: .t("PRSR001: If columns are deleted or renamed you may lose existing mappings.");
094: String dlgMsg = Localizer.parse(nbBundle3);
095:
096: String nbBundle4 = mLoc.t("PRSR001: Refresh Metadata");
097: String dlgTitle = Localizer.parse(nbBundle4);
098: int response = JOptionPane.showConfirmDialog(WindowManager
099: .getDefault().getMainWindow(), dlgMsg, dlgTitle,
100: JOptionPane.OK_CANCEL_OPTION,
101: JOptionPane.WARNING_MESSAGE);
102: if (JOptionPane.OK_OPTION == response) {
103: Iterator targetTables = model.getSQLDefinition()
104: .getTargetTables().iterator();
105: while (targetTables.hasNext()) {
106: try {
107: TargetTable tt = (TargetTable) targetTables.next();
108: SQLDBSynchronizationVisitor visitView = new SQLDBSynchronizationVisitor();
109: SQLTargetTableArea ttArea = (SQLTargetTableArea) graphView
110: .findGraphNode(tt);
111: SQLTableArea tarea = (SQLTableArea) ttArea
112: .getTableArea();
113: MetaTableModel metaModel = (MetaTableModel) tarea
114: .getModel();
115: visitView.mergeCollabTableWithDatabaseTable(
116: (SQLDBTable) tt, metaModel);
117: if (!visitView.infoList.isEmpty()) {
118: ttArea.layoutChildren();
119: // Mark collab as needing to be persisted.
120: DataObjectProvider.getProvider()
121: .getActiveDataObject()
122: .setModified(true);
123: model.setDirty(true);
124: infoList.addAll(visitView.infoList);
125: }
126: } catch (DBSQLException ex) {
127: Exceptions.printStackTrace(ex);
128: } catch (Exception ex) {
129: Exceptions.printStackTrace(ex);
130: }
131: }
132:
133: Iterator sourceTables = model.getSQLDefinition()
134: .getSourceTables().iterator();
135: while (sourceTables.hasNext()) {
136: try {
137: SourceTable st = (SourceTable) sourceTables.next();
138: SQLDBSynchronizationVisitor visitView = new SQLDBSynchronizationVisitor();
139: SQLSourceTableArea stArea = (SQLSourceTableArea) graphView
140: .findGraphNode(st);
141: SQLTableArea tarea = (SQLTableArea) stArea
142: .getTableArea();
143: MetaTableModel metaModel = (MetaTableModel) tarea
144: .getModel();
145: visitView.mergeCollabTableWithDatabaseTable(
146: (SQLDBTable) st, metaModel);
147: if (!visitView.infoList.isEmpty()) {
148: stArea.layoutChildren();
149: SQLJoinView jView = model.getJoinView(st);
150: if (jView != null) {
151: JoinViewGraphNode jViewGraph = (JoinViewGraphNode) graphView
152: .findGraphNode(jView);
153: jViewGraph.layoutChildren();
154: jViewGraph.setHeight(jViewGraph
155: .getMaximumHeight());
156: }
157: // Mark collab as needing to be persisted.
158: DataObjectProvider.getProvider()
159: .getActiveDataObject()
160: .setModified(true);
161: model.setDirty(true);
162: infoList.addAll(visitView.infoList);
163: }
164: } catch (DBSQLException ex) {
165: Exceptions.printStackTrace(ex);
166: } catch (Exception ex) {
167: Exceptions.printStackTrace(ex);
168: }
169: }
170: BasicTopView gvMgr = (BasicTopView) graphView
171: .getGraphViewContainer();
172: gvMgr.showRefreshMetadataInfo(infoList);
173: } // end of jOptionPane
174: }
175: }
|