use of net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab in project tdq-studio-se by Talend.
the class SQLEditor method createResultsTab.
/**
* Allocates a new tab for an AbstractSQLExecution; the tab and it's contents are completely undefined
*
* @param sqlExec
* @return
*/
public ResultsTab createResultsTab(AbstractSQLExecution job) {
if (tabFolder.isDisposed()) {
return null;
}
// Create the new tab, make it second to last (IE keep the messages tab
// always at the end) and set the new tab's title to the 1-based index
CTabItem tabItem = new CTabItem(tabFolder, SWT.CLOSE, tabFolder.getItems().length - 1);
tabItem.setText(Integer.toString(tabFolder.getItems().length - 1));
tabFolder.setSelection(tabItem);
// Make sure we can track the execution
tabItem.setData(job);
// Create a composite to add all controls to
Composite composite = new Composite(tabFolder, SWT.NONE);
tabItem.setControl(composite);
// Make sure we're visible
getSite().getPage().bringToTop(this);
return new ResultsTab(this, tabItem, composite);
}
use of net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab in project tdq-studio-se by Talend.
the class SQLExecution method displayResults.
/**
* Display SQL Results in result pane
* @param sqlResult the results of the query
*/
protected void displayResults(final SQLResult sqlResult) {
// Switch to the UI thread to execute this
getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
ResultsTab resultsTab = allocateResultsTab(sqlResult.getQuery());
if (resultsTab == null)
return;
String caption = sqlResult.getDataSet().getCaption();
if (caption != null)
resultsTab.getTabItem().setText(caption);
try {
// set initial message
setProgressMessage(Messages.getString("SQLResultsView.ConnectionWait"));
Composite composite = resultsTab.getParent();
GridLayout gLayout = new GridLayout();
gLayout.numColumns = 2;
gLayout.marginLeft = 0;
gLayout.horizontalSpacing = 0;
gLayout.verticalSpacing = 0;
gLayout.marginWidth = 0;
gLayout.marginHeight = 0;
composite.setLayout(gLayout);
int resultCount = sqlResult.getDataSet().getRows().length;
String statusMessage = Messages.getString("SQLResultsView.Time.Prefix") + " " + sqlResult.getExecutionTimeMillis() + " " + Messages.getString("SQLResultsView.Time.Postfix");
getEditor().setMessage(statusMessage);
if (resultCount > 0)
statusMessage = statusMessage + " " + Messages.getString("SQLResultsView.Count.Prefix") + " " + resultCount;
Query sql = sqlResult.getQuery();
int lineNo = sql.getLineNo();
lineNo = getQueryParser().adjustLineNo(lineNo);
getEditor().addMessage(new Message(Message.Status.SUCCESS, lineNo, 0, sql.getQuerySql(), statusMessage));
new DataSetTable(composite, sqlResult.getDataSet(), statusMessage);
composite.setData("parenttab", resultsTab.getTabItem());
composite.layout();
composite.redraw();
// reset to start message in case F5 will be used
setProgressMessage(Messages.getString("SQLResultsView.ConnectionWait"));
} catch (Exception e) {
// add message
if (resultsTab != null) {
String message = e.getMessage();
Label errorLabel = new Label(resultsTab.getParent(), SWT.FILL);
errorLabel.setText(message);
errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
}
SQLExplorerPlugin.error("Error creating result tab", e);
}
}
});
}
use of net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab in project tdq-studio-se by Talend.
the class AbstractSQLExecution method allocateResultsTab.
/**
* Creates a new tab for the results in SQLEditor
* @return
*/
protected ResultsTab allocateResultsTab(Query query) {
ResultsTab resultsTab = _editor.createResultsTab(this);
if (resultsTab == null)
return null;
boolean longCaptions = SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.USE_LONG_CAPTIONS_ON_RESULTS);
if (longCaptions) {
String caption = resultsTab.getTabItem().getText() + " [" + TextUtil.compressWhitespace(query.getQuerySql(), MAX_CAPTION_LENGTH) + "]";
resultsTab.getTabItem().setText(caption);
}
return resultsTab;
}
use of net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab in project tdq-studio-se by Talend.
the class ExplainExecution method displayResults.
private void displayResults(final ExplainNode node, final Query query) {
getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
ResultsTab resultsTab = allocateResultsTab(query);
try {
Composite composite = resultsTab.getParent();
GridLayout gLayout = new GridLayout();
gLayout.numColumns = 2;
gLayout.marginLeft = 0;
gLayout.horizontalSpacing = 0;
gLayout.verticalSpacing = 0;
gLayout.marginWidth = 0;
gLayout.marginHeight = 0;
composite.setLayout(gLayout);
composite.setData("parenttab", resultsTab.getTabItem());
Composite pp = new Composite(composite, 0);
pp.setLayout(new FillLayout());
pp.setLayoutData(new GridData(1808));
TableTreeViewer tv = new TableTreeViewer(pp, 0x10800);
Table table = tv.getTableTree().getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn tc = new TableColumn(table, 0);
tc.setText("");
tc = new TableColumn(table, 0);
tc.setText("Cost");
tc = new TableColumn(table, 0);
tc.setText("Cardinality");
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(new ColumnWeightData(6, 150, true));
tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
table.setLayout(tableLayout);
tv.setContentProvider(new ITreeContentProvider() {
public void dispose() {
}
public Object[] getChildren(Object parentElement) {
return ((ExplainNode) parentElement).getChildren();
}
public Object[] getElements(Object inputElement) {
ExplainNode nd = (ExplainNode) inputElement;
return nd.getChildren();
}
public Object getParent(Object element) {
return ((ExplainNode) element).getParent();
}
public boolean hasChildren(Object element) {
return ((ExplainNode) element).getChildren().length > 0;
}
public void inputChanged(Viewer viewer1, Object obj, Object obj1) {
}
});
tv.setLabelProvider(new TreeLabelProvider() {
});
tv.setInput(node);
tv.refresh();
tv.expandAll();
for (int i = 0; i < table.getColumnCount(); i++) table.getColumn(i).pack();
final ExplainPlanActionGroup actionGroup = new ExplainPlanActionGroup(tv, node.getChildren()[0]);
MenuManager menuManager = new MenuManager("ExplainPlanContextMenu");
menuManager.setRemoveAllWhenShown(true);
org.eclipse.swt.widgets.Menu contextMenu = menuManager.createContextMenu(table);
tv.getControl().setMenu(contextMenu);
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
actionGroup.fillContextMenu(manager);
}
});
composite.layout();
composite.redraw();
} catch (Exception e) {
if (resultsTab != null) {
Composite composite = resultsTab.getParent();
String message = e.getMessage();
Label errorLabel = new Label(composite, 4);
errorLabel.setText(message);
errorLabel.setLayoutData(new GridData(4, 128, true, false));
}
SQLExplorerPlugin.error("Error creating explain tab", e);
}
}
});
}
Aggregations