use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode in project tdq-studio-se by Talend.
the class RowCountTab method getDataSet.
public DataSet getDataSet() throws ExplorerException {
String nodeName = getNode().toString();
if (getNode() instanceof TableNode) {
TableNode tableNode = (TableNode) getNode();
nodeName = tableNode.getQualifiedName();
}
try {
// $NON-NLS-1$
return new DataSet(null, "select count(*) from " + nodeName, null, getNode().getSession());
} catch (SQLException e) {
throw new ExplorerException(e);
}
}
use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode in project tdq-studio-se by Talend.
the class ExportedKeysTab method getDataSet.
public DataSet getDataSet() throws Exception {
INode node = getNode();
if (node == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
ResultSet resultSet = node.getSession().getMetaData().getExportedKeys(tableNode.getTableInfo());
DataSet dataSet = new DataSet(resultSet, new int[] { 4, 7, 8, 9, 10, 11, 12, 13, 14 });
resultSet.close();
return dataSet;
}
return null;
}
use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode in project tdq-studio-se by Talend.
the class ColumnInfoTab method getDataSet.
@Override
public DataSet getDataSet() {
INode node = getNode();
if (node == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
DataSet dataSet = null;
// something(.e.g,ResultSetColumnReader.getLong(16))
try {
TableColumnInfo[] cols = node.getSession().getMetaData().getColumnInfo(tableNode.getTableInfo());
Comparable[][] dataRows = new Comparable[cols.length][];
int index = 0;
for (TableColumnInfo col : cols) {
Comparable[] row = new Comparable[COLUMN_LABELS.length];
dataRows[index++] = row;
int i = 0;
row[i++] = col.getColumnName();
row[i++] = col.getDataType();
row[i++] = col.getTypeName();
row[i++] = col.getColumnSize();
row[i++] = col.getDecimalDigits();
row[i++] = col.getRadix();
row[i++] = col.isNullAllowed();
row[i++] = col.getRemarks();
row[i++] = col.getDefaultValue();
row[i++] = col.getOctetLength();
row[i++] = col.getOrdinalPosition();
row[i++] = col.isNullable();
if (i != COLUMN_LABELS.length) {
throw new RuntimeException(Messages.getString("ColumnInfoTab.runtimeException"));
}
}
dataSet = new DataSet(COLUMN_LABELS, dataRows);
} catch (Exception e) {
SQLExplorerPlugin.error(Messages.getString("AbstractDataSetTab.error"), e);
boolean isODBCTeradata = false;
try {
isODBCTeradata = ConnectionUtils.isOdbcTeradata(node.getSession().getMetaData().getJDBCMetaData()) ? true : false;
} catch (SQLException e1) {
SQLExplorerPlugin.error("Failed to get the type of Database", e);
}
if (isODBCTeradata) {
MessageDialog.openError(Display.getDefault().getActiveShell(), "unsupported", "This operation is unsupported by ODBC Teradata in SQLExplorer!");
}
}
return dataSet;
}
return null;
}
use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode in project tdq-studio-se by Talend.
the class SQLCompletionProcessor method computeCompletionProposals.
/**
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
* int)
*/
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
if (dictionary == null)
return null;
String text = viewer.getDocument().get();
String string = text.substring(0, documentOffset);
if (// $NON-NLS-1$
string.equals(""))
return null;
int position = string.length() - 1;
char character;
while (position > 0) {
character = string.charAt(position);
if (!Character.isJavaIdentifierPart(character) && (character != '.'))
break;
--position;
}
if (position == 0)
position = -1;
string = string.substring(position + 1);
// JFaceDbcPlugin.error("String: "+string,new Exception());
if (string == null || string.equals(""))
return null;
string = string.toLowerCase();
int length = string.length();
if (length < 1)
return null;
// $NON-NLS-1$
int dotIndex = string.lastIndexOf(".");
if (string.charAt(length - 1) == ' ') {
return null;
} else if (string.charAt(length - 1) == '.') {
// Last typed character
// is '.'
String name = string.substring(0, length - 1);
if (name == null)
return null;
int otherDot = name.lastIndexOf(".");
if (otherDot != -1)
name = name.substring(otherDot + 1);
if (name == null || name.equals(""))
return null;
TreeSet st = (TreeSet) dictionary.getColumnListByTableName(name);
if (st != null) {
ArrayList list = (ArrayList) dictionary.getByTableName(name);
if (list == null)
return null;
TableNode nd = null;
if (list.size() == 1)
nd = (TableNode) list.get(0);
else
return null;
Object[] obj = st.toArray();
String[] arr = new String[obj.length];
System.arraycopy(obj, 0, arr, 0, obj.length);
ICompletionProposal[] result = new ICompletionProposal[arr.length];
String tableDesc = null;
if (nd != null)
tableDesc = nd.getTableDesc();
for (int i = 0; i < arr.length; i++) {
result[i] = new CompletionProposal(arr[i], documentOffset, 0, arr[i].length(), colImage, arr[i], null, tableDesc);
}
return result;
}
INode node = (INode) dictionary.getByCatalogSchemaName(name);
if (node != null) {
Object[] children = (Object[]) node.getChildNodes();
ArrayList propList = new ArrayList();
if (children != null) {
for (int i = 0; i < children.length; i++) {
String childName = children[i].toString().toLowerCase();
if (childName.equals("table") || childName.equals("view")) {
Object[] tables = (Object[]) ((INode) children[i]).getChildNodes();
if (tables != null) {
for (int j = 0; j < tables.length; j++) {
Image tmpImage = null;
String tableName = tables[j].toString();
if (tables[j] instanceof TableNode) {
if (((TableNode) tables[j]).isTable())
tmpImage = tableImage;
else if (((TableNode) tables[j]).isView())
tmpImage = viewImage;
propList.add(new ExtendedCompletionProposal(tableName, documentOffset, 0, tableName.length(), tmpImage, tableName, (TableNode) tables[j]));
}
}
}
}
}
}
ICompletionProposal[] res = new ICompletionProposal[propList.size()];
System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
Arrays.sort(res, new ICompletionProposalComparator());
return res;
}
} else if (// The string does not contain "."
dotIndex == -1) {
String[] keywordProposal = Dictionary.matchKeywordsPrefix(string);
ICompletionProposal[] resKey = new ICompletionProposal[keywordProposal.length];
for (int i = 0; i < keywordProposal.length; i++) {
resKey[i] = new CompletionProposal(keywordProposal[i], documentOffset - length, length, keywordProposal[i].length(), keywordImage, keywordProposal[i], null, null);
}
String[] proposalsString = dictionary.matchTablePrefix(string.toLowerCase());
ArrayList propList = new ArrayList();
for (int i = 0; i < proposalsString.length; i++) {
ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
for (int j = 0; j < ls.size(); j++) {
TableNode tbNode = (TableNode) ls.get(j);
Image tmpImage = null;
if (tbNode.isView())
tmpImage = viewImage;
else if (tbNode.isTable())
tmpImage = tableImage;
ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - length, length, proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
propList.add(cmp);
}
}
String[] proposalsString2 = dictionary.matchCatalogSchemaPrefix(string.toLowerCase());
ICompletionProposal[] resKey2 = new ICompletionProposal[proposalsString2.length];
for (int i = 0; i < proposalsString2.length; i++) {
resKey2[i] = new CompletionProposal(proposalsString2[i], documentOffset - length, length, proposalsString2[i].length(), catalogImage, proposalsString2[i], null, null);
}
ICompletionProposal[] res = new ICompletionProposal[propList.size() + keywordProposal.length + resKey2.length];
System.arraycopy(resKey, 0, res, 0, resKey.length);
System.arraycopy(propList.toArray(), 0, res, resKey.length, propList.size());
System.arraycopy(resKey2, 0, res, resKey.length + propList.size(), resKey2.length);
Arrays.sort(res, new ICompletionProposalComparator());
return res;
} else if (dotIndex != -1) {
String firstPart = string.substring(0, dotIndex);
int otherDot = firstPart.indexOf(".");
if (otherDot != -1)
firstPart = firstPart.substring(otherDot + 1);
String lastPart = string.substring(dotIndex + 1);
if (lastPart == null || firstPart == null || lastPart.equals("") || firstPart.equals(""))
return null;
TreeSet st = (TreeSet) dictionary.getColumnListByTableName(firstPart);
if (st != null) {
Iterator iter = st.iterator();
ArrayList propList = new ArrayList();
while (iter.hasNext()) {
String colName = (String) iter.next();
int length2 = lastPart.length();
if (colName.length() >= length2) {
if ((colName.substring(0, lastPart.length())).equalsIgnoreCase(lastPart)) {
CompletionProposal cmp = new CompletionProposal(colName, documentOffset - length2, length2, colName.length(), colImage, colName, null, null);
propList.add(cmp);
}
}
}
ICompletionProposal[] res = new ICompletionProposal[propList.size()];
System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
return res;
}
INode node = (INode) dictionary.getByCatalogSchemaName(firstPart);
if (node != null) {
String[] proposalsString = dictionary.matchTablePrefix(lastPart.toLowerCase());
ArrayList propList = new ArrayList();
for (int i = 0; i < proposalsString.length; i++) {
ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
for (int j = 0; j < ls.size(); j++) {
TableNode tbNode = (TableNode) ls.get(j);
Image tmpImage = null;
TableFolderNode totn = (TableFolderNode) tbNode.getParent();
INode catSchema = (INode) totn.getParent();
if (catSchema == node) {
if (tbNode.isView())
tmpImage = viewImage;
else if (tbNode.isTable())
tmpImage = tableImage;
ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - lastPart.length(), lastPart.length(), proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
propList.add(cmp);
}
}
}
ICompletionProposal[] res = new ICompletionProposal[propList.size()];
System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
return res;
}
}
return null;
}
use of net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode 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