use of net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode in project tdq-studio-se by Talend.
the class DetailTabManager method createTabs.
/**
* Returns a list of all available tabs for a given node. These tabs can be
* standard or plugin tabs.
*
* @param node for which to find tabs.
* @return List of tabs
*/
private static List<IDetailTab> createTabs(INode node) {
if (_logger.isDebugEnabled()) {
// $NON-NLS-1$
_logger.debug("Creating tabs for: " + node.getUniqueIdentifier());
}
ArrayList<IDetailTab> tabList = new ArrayList<IDetailTab>();
// create connection info tab if needed
if (node instanceof DatabaseNode) {
IDetailTab dbTab = new ConnectionInfoTab();
dbTab.setNode(node);
tabList.add(dbTab);
}
// create our basic table tabs
if (node instanceof TableNode) {
IDetailTab tab1 = new ColumnInfoTab();
IDetailTab tab2 = new TableInfoTab();
IDetailTab tab3 = new PreviewTab();
IDetailTab tab4 = new RowCountTab();
IDetailTab tab5 = new PrimaryKeysTab();
IDetailTab tab6 = new ExportedKeysTab();
IDetailTab tab7 = new ImportedKeysTab();
IDetailTab tab8 = new IndexesTab();
IDetailTab tab9 = new PriviligesTab();
IDetailTab tab10 = new ColumnPriviligesTab();
IDetailTab tab11 = new RowIdsTab();
IDetailTab tab12 = new VersionsTab();
tab1.setNode(node);
tab2.setNode(node);
tab3.setNode(node);
tab4.setNode(node);
tab5.setNode(node);
tab6.setNode(node);
tab7.setNode(node);
tab8.setNode(node);
tab9.setNode(node);
tab10.setNode(node);
tab11.setNode(node);
tab12.setNode(node);
tabList.add(tab1);
tabList.add(tab2);
tabList.add(tab3);
tabList.add(tab4);
tabList.add(tab5);
tabList.add(tab6);
tabList.add(tab7);
tabList.add(tab8);
tabList.add(tab9);
tabList.add(tab10);
tabList.add(tab11);
tabList.add(tab12);
}
// create extension point tabs
String databaseProductName = node.getSession().getRoot().getDatabaseProductName().toLowerCase().trim();
String nodeType = node.getType().toLowerCase().trim();
IExtensionRegistry registry = Platform.getExtensionRegistry();
// $NON-NLS-1$ $NON-NLS-2$
IExtensionPoint point = registry.getExtensionPoint("net.sourceforge.sqlexplorer", "nodeDetailTab");
IExtension[] extensions = point.getExtensions();
for (int i = 0; i < extensions.length; i++) {
IExtension e = extensions[i];
IConfigurationElement[] ces = e.getConfigurationElements();
for (int j = 0; j < ces.length; j++) {
try {
boolean isValidProduct = false;
boolean isValidNodeType = false;
// $NON-NLS-1$ $NON-NLS-2$
String[] validProducts = ces[j].getAttribute("database-product-name").split(",");
// $NON-NLS-1$ $NON-NLS-2$
String[] validNodeTypes = ces[j].getAttribute("node-type").split(",");
// check if tab is valid for current database product
for (int k = 0; k < validProducts.length; k++) {
String product = validProducts[k].toLowerCase().trim();
if (product.length() == 0) {
continue;
}
if (product.equals("*")) {
// $NON-NLS-1$
isValidProduct = true;
break;
}
// $NON-NLS-1$ $NON-NLS-2$
String regex = TextUtil.replaceChar(product, '*', ".*");
if (databaseProductName.matches(regex)) {
isValidProduct = true;
break;
}
}
if (!isValidProduct) {
continue;
}
// check if tab is valid for current node type
for (int k = 0; k < validNodeTypes.length; k++) {
String type = validNodeTypes[k].toLowerCase().trim();
if (type.length() == 0) {
continue;
}
if (type.equals("*")) {
// $NON-NLS-1$
isValidNodeType = true;
break;
}
// $NON-NLS-1$ $NON-NLS-2$
String regex = TextUtil.replaceChar(type, '*', ".*");
if (nodeType.matches(regex)) {
isValidNodeType = true;
break;
}
}
if (!isValidNodeType) {
continue;
}
// add tab to list
// $NON-NLS-1$
IDetailTab tab = (IDetailTab) ces[j].createExecutableExtension("class");
tab.setNode(node);
tabList.add(tab);
} catch (Throwable ex) {
SQLExplorerPlugin.error(Messages.getString("DataSetTableActionGroup.cannotCreateMenuAction"), ex);
}
}
}
return tabList;
}
use of net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode in project tdq-studio-se by Talend.
the class RefreshNodeAction method run.
/**
* Refresh selected node and descendants.
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
// clear cache for all nodes
for (int i = 0; i < _selectedNodes.length; i++) {
if (_selectedNodes[i] instanceof DatabaseNode) {
// clear detail cache for session
DetailTabManager.clearCacheForSession(_selectedNodes[i].getSession());
break;
} else {
// clear detail cache for node.
DetailTabManager.clearCacheForNode(_selectedNodes[i]);
}
}
// refresh nodes
for (int i = 0; i < _selectedNodes.length; i++) {
_selectedNodes[i].refresh();
}
// refresh structure view
DatabaseStructureView structureView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
_treeViewer.refresh();
// refresh detail view
DatabaseDetailView detailView = (DatabaseDetailView) SQLExplorerPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
structureView.synchronizeDetailView(detailView);
}
use of net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode in project tdq-studio-se by Talend.
the class SqlexplorerService method findSqlExplorerTableNode.
/*
* (non-Javadoc)
*
* @see
* org.talend.dataprofiler.service.ISqlexplorerService#findSqlExplorerTableNode(org.talend.core.model.metadata.builder
* .connection.Connection, orgomg.cwm.objectmodel.core.Package, java.lang.String, java.lang.String)
*/
@Override
public void findSqlExplorerTableNode(Connection providerConnection, Package parentPackageElement, String tableName, String activeTabName) {
// Open data explore perspective.
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
ITDQRepositoryService service = (ITDQRepositoryService) GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
if (service != null) {
service.changePerspectiveAction(SQLExplorerPluginPerspective.class.getName());
} else {
return;
}
}
Collection<Alias> aliases = SQLExplorerPlugin.getDefault().getAliasManager().getAliases();
String url = JavaSqlFactory.getURL(providerConnection);
User currentUser = null;
for (Alias alias : aliases) {
if (alias.getUrl().equals(url)) {
currentUser = alias.getDefaultUser();
OpenPasswordConnectDialogAction openDlgAction = new OpenPasswordConnectDialogAction(alias, alias.getDefaultUser(), false);
openDlgAction.run();
break;
}
}
// MOD qiongli bug 13093,2010-7-2,show the warning dialog when the table can't be found
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
if (currentUser == null) {
// $NON-NLS-1$
MessageDialog.openWarning(// $NON-NLS-1$
shell, // $NON-NLS-1$
Messages.getString("SqlExplorerBridge.Warning"), // $NON-NLS-1$
Messages.getString("SqlExplorerBridge.MissTable") + tableName);
return;
}
DatabaseNode root = currentUser.getMetaDataSession().getRoot();
root.load();
List<INode> catalogs = root.getCatalogs();
List<INode> schemas = root.getSchemas();
Catalog catalog = SwitchHelpers.CATALOG_SWITCH.doSwitch(parentPackageElement);
Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(parentPackageElement);
INode catalogOrSchemaNode = null;
// TDQ-12005: fix Exasol/hive(TDQ-11887: hdp20 at least) database can view index/keys well
String findCatalogNodeName = isExasol(url) ? "EXA_DB" : (isHive(url) ? "NoCatalog" : "");
if (!findCatalogNodeName.equals("") && !catalogs.isEmpty()) {
for (INode catalogNode : catalogs) {
if (findCatalogNodeName.equalsIgnoreCase(catalogNode.getName())) {
catalogOrSchemaNode = catalogNode;
break;
}
}
} else {
if (catalog != null) {
// MOD klliu bug 14662 2010-08-05
if (!catalogs.isEmpty()) {
for (INode catalogNode : catalogs) {
if (parentPackageElement.getName().equalsIgnoreCase(catalogNode.getName())) {
catalogOrSchemaNode = catalogNode;
break;
}
}
} else {
catalogOrSchemaNode = root;
}
} else {
// MOD by zshen for 20517
if (schemas.isEmpty()) {
// the case for mssql/postgrel(which have catalog and schema structor) schema analysis.
Catalog shcmeaOfCatalogNode = CatalogHelper.getParentCatalog(parentPackageElement);
for (INode catalogNode : catalogs) {
if (shcmeaOfCatalogNode != null && shcmeaOfCatalogNode.getName().equalsIgnoreCase(catalogNode.getName())) {
catalogOrSchemaNode = catalogNode;
break;
}
}
}
for (INode schemaNode : schemas) {
if (parentPackageElement.getName().equalsIgnoreCase(schemaNode.getName())) {
catalogOrSchemaNode = schemaNode;
break;
}
}
}
}
// find the table folder node.
if (catalogOrSchemaNode == null) {
// $NON-NLS-1$
throw new NullPointerException(Messages.getString("SqlExplorerBridge.CATORSCHMISNULL"));
}
// catalog node.
if (schema != null) {
if (catalogOrSchemaNode.getSchemaName() == null) {
catalogOrSchemaNode.setSchemaName(schema.getName());
} else if (!StringUtils.equals(catalogOrSchemaNode.getSchemaName(), schema.getName())) {
// if this catalog already loaded its children of some schema, should reload for this schema.
if (catalogOrSchemaNode.isChildrenLoaded()) {
SQLExplorerPlugin.getDefault().getDatabaseStructureView().refreshSessionTrees(currentUser.getMetaDataSession());
List<INode> catalogs2 = currentUser.getMetaDataSession().getRoot().getCatalogs();
if (catalogs2.size() != 0) {
for (INode catalogNode : catalogs2) {
if (catalogOrSchemaNode.getName().equalsIgnoreCase(catalogNode.getName())) {
catalogOrSchemaNode = catalogNode;
catalogOrSchemaNode.setSchemaName(schema.getName());
break;
}
}
}
}
}
}
// ~
INode[] childNodes = catalogOrSchemaNode.getChildNodes();
// need to find the schema and load the table nodes
if (isNetezza(url)) {
SchemaNode sNode = getNetezzaSchema(childNodes, JavaSqlFactory.getUsername(providerConnection));
if (sNode != null) {
childNodes = sNode.getChildNodes();
}
}
TableFolderNode tableFolderNode = null;
for (INode node : childNodes) {
if ("TABLE".equals(node.getQualifiedName())) {
// $NON-NLS-1$
tableFolderNode = (TableFolderNode) node;
break;
}
}
if (tableFolderNode == null) {
// $NON-NLS-1$
log.fatal(Messages.getString("SqlExplorerBridge.TABLE_FOLDER_NULL0"));
} else {
INode[] tableNodes = tableFolderNode.getChildNodes();
for (INode node : tableNodes) {
if (tableName.equalsIgnoreCase(node.getName())) {
DetailTabManager.setActiveTabName(activeTabName);
DatabaseStructureView dsView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
dsView.setSessionSelectionNode(currentUser.getMetaDataSession(), new StructuredSelection(node));
// MOD qiongli bug 13093,2010-7-2
SQLExplorerPlugin.getDefault().getConnectionsView().getTreeViewer().setSelection(new StructuredSelection(currentUser));
return;
}
}
}
// $NON-NLS-1$
MessageDialog.openWarning(// $NON-NLS-1$
shell, // $NON-NLS-1$
Messages.getString("SqlExplorerBridge.Warning"), // $NON-NLS-1$
Messages.getString("SqlExplorerBridge.MissTable") + tableName);
}
use of net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode in project tdq-studio-se by Talend.
the class DatabaseStructureView method addSession.
/**
* Add a new session to the database structure view. This will create a new tab for the session.
*
* @param session
*/
private void addSession(final MetaDataSession session) throws SQLCannotConnectException {
if (_allSessions.contains(session)) {
return;
}
try {
session.getMetaData();
session.setAutoCommit(true);
} catch (SQLCannotConnectException e) {
SQLExplorerPlugin.error(e);
throw e;
} catch (SQLException e) {
SQLExplorerPlugin.error(e);
MessageDialog.openError(getSite().getShell(), "Cannot connect", e.getMessage());
}
DatabaseNode rootNode = session.getRoot();
if (rootNode == null) {
return;
}
_allSessions.add(session);
if (_filterAction != null) {
_filterAction.setEnabled(true);
}
if (_tabFolder == null || _tabFolder.isDisposed()) {
clearParent();
// create tab folder for different sessions
_tabFolder = new CTabFolder(_parent, SWT.TOP | SWT.CLOSE);
// add listener to keep both views on the same active tab
_tabFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// set the selected node in the detail view.
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
synchronizeDetailView(detailView);
}
});
// Set up a gradient background for the selected tab
Display display = getSite().getShell().getDisplay();
_tabFolder.setSelectionBackground(new Color[] { display.getSystemColor(SWT.COLOR_WHITE), new Color(null, 211, 225, 250), new Color(null, 175, 201, 246), IConstants.TAB_BORDER_COLOR }, new int[] { 25, 50, 75 }, true);
// Add a listener to handle the close button on each tab
_tabFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {
@Override
public void close(CTabFolderEvent event) {
CTabItem tabItem = (CTabItem) event.item;
TabData tabData = (TabData) tabItem.getData();
_allSessions.remove(tabData.session);
event.doit = true;
}
});
_parent.layout();
_parent.redraw();
}
// create tab
final CTabItem tabItem = new CTabItem(_tabFolder, SWT.NULL);
TabData tabData = new TabData();
tabItem.setData(tabData);
tabData.session = session;
// set tab text
String labelText = session.getUser().getDescription();
tabItem.setText(labelText);
// create composite for our outline
Composite composite = new Composite(_tabFolder, SWT.NULL);
composite.setLayout(new FillLayout());
tabItem.setControl(composite);
// create outline
final TreeViewer treeViewer = new TreeViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER);
tabData.treeViewer = treeViewer;
// add drag support
// TODO improve drag support options
Transfer[] transfers = new Transfer[] { TableNodeTransfer.getInstance() };
treeViewer.addDragSupport(DND.DROP_COPY, transfers, new DragSourceListener() {
public void dragFinished(DragSourceEvent event) {
System.out.println("$drag finished");
TableNodeTransfer.getInstance().setSelection(null);
}
public void dragSetData(DragSourceEvent event) {
Object sel = ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
event.data = sel;
}
public void dragStart(DragSourceEvent event) {
event.doit = !treeViewer.getSelection().isEmpty();
if (event.doit) {
Object sel = ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
if (!(sel instanceof TableNode)) {
event.doit = false;
} else {
TableNode tn = (TableNode) sel;
TableNodeTransfer.getInstance().setSelection(tn);
if (!tn.isTable()) {
event.doit = false;
}
}
}
}
});
// use hash lookup to improve performance
treeViewer.setUseHashlookup(true);
// add content and label provider
treeViewer.setContentProvider(new DBTreeContentProvider());
treeViewer.setLabelProvider(new DBTreeLabelProvider());
// set input session
treeViewer.setInput(rootNode);
// add selection change listener, so we can update detail view as
// required.
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent ev) {
// set the selected node in the detail view.
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
synchronizeDetailView(detailView);
}
});
// bring detail to front on doubleclick of node
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
try {
// find view
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
if (detailView == null) {
getSite().getPage().showView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
}
getSite().getPage().bringToTop(detailView);
synchronizeDetailView(detailView);
} catch (Exception e) {
// fail silent
}
}
});
// add expand/collapse listener
treeViewer.addTreeListener(new ITreeViewerListener() {
public void treeCollapsed(TreeExpansionEvent event) {
// refresh the node to change image
INode node = (INode) event.getElement();
node.setExpanded(false);
TreeViewer viewer = (TreeViewer) event.getSource();
viewer.update(node, null);
}
public void treeExpanded(TreeExpansionEvent event) {
// refresh the node to change image
INode node = (INode) event.getElement();
node.setExpanded(true);
TreeViewer viewer = (TreeViewer) event.getSource();
viewer.update(node, null);
}
});
// set new tab as the active one
_tabFolder.setSelection(_tabFolder.getItemCount() - 1);
// update detail view
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
if (detailView != null) {
// synchronze detail view with new session
synchronizeDetailView(detailView);
// bring detail to top of the view stack
getSite().getPage().bringToTop(detailView);
}
// refresh view
composite.layout();
_tabFolder.layout();
_tabFolder.redraw();
// bring this view to top of the view stack, above detail if needed..
getSite().getPage().bringToTop(this);
// add context menu
final DBTreeActionGroup actionGroup = new DBTreeActionGroup(treeViewer);
MenuManager menuManager = new MenuManager("DBTreeContextMenu");
menuManager.setRemoveAllWhenShown(true);
Menu contextMenu = menuManager.createContextMenu(treeViewer.getTree());
treeViewer.getTree().setMenu(contextMenu);
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
actionGroup.fillContextMenu(manager);
}
});
// if (sessionSelectionMap.containsKey(tabData.session)) {
// tabData.treeViewer.setSelection(sessionSelectionMap.get(tabData.session));
// sessionSelectionMap.remove(tabData.session);
// _allSessions.remove(tabData.session);
// }
}
Aggregations