use of net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView in project tdq-studio-se by Talend.
the class FilterStructureAction method run.
public void run() {
try {
DatabaseStructureView view = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
FilterStructureDialog dialog = new FilterStructureDialog();
Session session = view.getSession();
if (session == null)
return;
Alias alias = session.getUser().getAlias();
if (alias.getSchemaFilterExpression() != null && alias.getSchemaFilterExpression().length() != 0) {
dialog.setSchemaFilter(alias.getSchemaFilterExpression().split(","));
}
if (alias.getFolderFilterExpression() != null && alias.getFolderFilterExpression().length() != 0) {
dialog.setFolderFilter(alias.getFolderFilterExpression().split(","));
}
if (alias.getNameFilterExpression() != null && alias.getNameFilterExpression().length() != 0) {
dialog.setNameFilter(alias.getNameFilterExpression());
}
if (dialog.open() != Window.OK) {
return;
}
String[] schemaFilter = dialog.getSchemaFilter();
StringBuffer schemaFilterString = new StringBuffer("");
String sep = "";
if (schemaFilter != null) {
for (int i = 0; i < schemaFilter.length; i++) {
schemaFilterString.append(sep);
schemaFilterString.append(schemaFilter[i]);
sep = ",";
}
}
alias.setSchemaFilterExpression(schemaFilterString.toString());
String[] folderFilter = dialog.getFolderFilter();
StringBuffer folderFilterString = new StringBuffer("");
sep = "";
if (folderFilter != null) {
for (int i = 0; i < folderFilter.length; i++) {
folderFilterString.append(sep);
folderFilterString.append(folderFilter[i]);
sep = ",";
}
}
alias.setFolderFilterExpression(folderFilterString.toString());
alias.setNameFilterExpression(dialog.getNameFilter());
view.refreshSessionTrees(view.getSession());
} catch (Exception e) {
SQLExplorerPlugin.error("Error creating dialog", e);
}
}
use of net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView 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.plugin.views.DatabaseStructureView 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.plugin.views.DatabaseStructureView in project tdq-studio-se by Talend.
the class SQLExplorerPlugin method startDefaultConnections.
/**
* Open all connections that have the 'open on startup property'. This method should be called from within the UI
* thread!
*/
public void startDefaultConnections(ConnectionsView connectionsView) {
this.connectionsView = connectionsView;
if (_defaultConnectionsStarted) {
return;
}
String fontDesc = getPluginPreferences().getString(IConstants.FONT);
FontData fontData = null;
try {
try {
fontData = new FontData(fontDesc);
} catch (IllegalArgumentException e) {
fontData = new FontData("1|Courier New|10|0|WINDOWS|1|-13|0|0|0|400|0|0|0|0|3|2|1|49|Courier New");
}
PreferenceConverter.setValue(getPreferenceStore(), IConstants.FONT, fontData);
} catch (IllegalArgumentException e) {
error("Error setting font", e);
}
boolean openEditor = SQLExplorerPlugin.getDefault().getPluginPreferences().getBoolean(IConstants.AUTO_OPEN_EDITOR);
// Get the database structure view - NOTE: we don't use SQLExplorerPlugin.getDatabaseView()
// because it may not have an active page yet
DatabaseStructureView dbView = null;
IWorkbenchSite site = connectionsView.getSite();
if (site.getPage() != null) {
dbView = (DatabaseStructureView) site.getPage().findView(DatabaseStructureView.class.getName());
}
for (Alias alias : aliasManager.getAliases()) {
if (alias.isConnectAtStartup() && alias.isAutoLogon() && alias.getDefaultUser() != null) {
if (dbView != null) {
try {
dbView.addUser(alias.getDefaultUser());
} catch (SQLCannotConnectException e) {
// Ignore it; the problem is already in the log, we do not want to delay startup, and the
// problem will
// be apparent as soon as the user tries to use the connection
}
}
if (openEditor) {
SQLEditorInput input = new SQLEditorInput(SQL_EDITOR + SQLExplorerPlugin.getDefault().getEditorSerialNo() + SQL);
input.setUser(alias.getDefaultUser());
try {
site.getPage().openEditor(input, SQLEditor.class.getName());
} catch (PartInitException e) {
SQLExplorerPlugin.error("Cannot open SQL editor", e);
}
}
}
}
_defaultConnectionsStarted = true;
}
Aggregations