use of org.eclipse.ui.PartInitException in project ACS by ACS-Community.
the class ApplicationWorkbenchWindowAdvisor method postWindowOpen.
public void postWindowOpen() {
final IStatusLineManager status = getWindowConfigurer().getActionBarConfigurer().getStatusLineManager();
status.setMessage("Application starting...");
final Display display = getWindowConfigurer().getWindow().getShell().getDisplay();
// Disables the initial view
IViewReference[] views = getWindowConfigurer().getWindow().getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
for (int i = 0; i < views.length; i++) {
if (views[i].getId().compareTo(AlarmSystemView.ID) == 0)
((IMyViewPart) views[i].getView(false)).setEnabled(false);
}
boolean authenticated = false;
AuthenticationDialog d = new AuthenticationDialog(ApplicationWorkbenchWindowAdvisor.this.getWindowConfigurer().getWindow().getShell());
UserAuthenticator.Role role = null;
while (!authenticated) {
d.open();
UserAuthenticator userAuth = new UserAuthenticator();
try {
role = userAuth.authenticate(d.getUser(), d.getPassword());
} catch (UserAuthenticatorException e) {
d.setErrorMessage("Authentication unsuccessful");
continue;
} catch (IllegalArgumentException e) {
d.setErrorMessage("Please authenticate yourselve");
continue;
} finally {
status.setMessage("Authentication successful");
}
authenticated = true;
}
final UserAuthenticator.Role finalRole = role;
new Thread(new Runnable() {
@Override
public void run() {
AlarmSystemManager asm = AlarmSystemManager.getInstance(finalRole);
try {
display.asyncExec(new Runnable() {
public void run() {
status.setMessage("Connecting to Manager");
}
});
asm.connectToManager();
display.asyncExec(new Runnable() {
public void run() {
status.setMessage("Connecting to CDB DAL");
}
});
asm.connectToDAL();
display.asyncExec(new Runnable() {
public void run() {
status.setMessage("Loading contents from the CDB");
}
});
asm.loadFromCDB();
final String error = asm.checkCDB();
if (error.compareTo("") != 0) {
display.asyncExec(new Runnable() {
public void run() {
ErrorDialog edialog = new ErrorDialog(getWindowConfigurer().getWindow().getShell(), "CDB Error", "Error while checking CDB integrity", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", error), IStatus.ERROR);
edialog.setBlockOnOpen(true);
edialog.open();
}
});
}
} catch (Exception e) {
e.printStackTrace();
display.asyncExec(new Runnable() {
public void run() {
status.setErrorMessage("Couldn't successfully connect to AS configuation");
}
});
return;
}
/* If everything went OK:
* Show the other views
* Enable the widgets and inform the user */
display.asyncExec(new Runnable() {
public void run() {
IWorkbenchPage page = getWindowConfigurer().getWindow().getActivePage();
try {
if (finalRole == Role.Administrator || finalRole == Role.Operator) {
page.showView(SourcesView.ID, null, IWorkbenchPage.VIEW_VISIBLE);
page.showView(CategoriesView.ID, null, IWorkbenchPage.VIEW_VISIBLE);
page.showView(AlarmsView.ID, null, IWorkbenchPage.VIEW_VISIBLE);
page.showView(ReductionsView.ID, null, IWorkbenchPage.VIEW_VISIBLE);
page.showView("org.eclipse.pde.runtime.LogView", null, IWorkbenchPage.VIEW_VISIBLE);
}
} catch (PartInitException e) {
status.setErrorMessage("Cannot open other views");
}
IViewReference[] views = page.getViewReferences();
for (int i = 0; i < views.length; i++) {
if (views[i].getId().compareTo(AlarmSystemView.ID) == 0)
((IMyViewPart) views[i].getView(false)).setEnabled(true);
if (finalRole == Role.Operator)
if (views[i].getView(false) instanceof IMyViewPart)
((IMyViewPart) views[i].getView(false)).setReadOnly(true);
}
status.setMessage("Application started successfully");
}
});
}
}).start();
}
use of org.eclipse.ui.PartInitException in project cubrid-manager by CUBRID.
the class PstmtOneDataDialog method showResultSet.
/**
*
* Open the query editor and show result set
*
* @param parameterList List<PstmtParameter>
*/
private void showResultSet(List<PstmtParameter> parameterList) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
String querySql = sqlTxt.getText();
close();
IEditorPart editor = window.getActivePage().findEditor(editorInput);
if (editor == null) {
try {
editor = window.getActivePage().openEditor(editorInput, QueryEditorPart.ID);
} catch (PartInitException e) {
editor = null;
}
}
if (editor != null) {
window.getActivePage().bringToTop(editor);
QueryEditorPart queryEditor = ((QueryEditorPart) editor);
if (!queryEditor.isConnected() && database != null) {
queryEditor.connect(database);
}
String allInputSql = getCommentSqlValue(parameterList) + querySql;
List<List<PstmtParameter>> rowParameterList = new ArrayList<List<PstmtParameter>>();
rowParameterList.add(parameterList);
if (queryEditor.isConnected()) {
queryEditor.setQuery(allInputSql, querySql, rowParameterList, true, true, false);
}
}
}
use of org.eclipse.ui.PartInitException in project cubrid-manager by CUBRID.
the class OpenSchemaEditorAction method run.
/**
* Open the selected database Schema Editor. If basing on none-database
* node, open the ERD by a virtual database
*/
public void run() {
// FIXME move this logic to core module
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
Object[] obj = this.getSelectedObj();
CubridDatabase[] cubridDatabases = getDBNodes(obj);
for (int i = 0; i < cubridDatabases.length; i++) {
// multi db nodes
if (cubridDatabases[i].getDatabaseInfo() == null || !cubridDatabases[i].isLogined()) {
cubridDatabases[i] = ERVirtualDatabase.getInstance();
}
}
if (cubridDatabases.length == 0) {
// when right-click not database nodes
cubridDatabases = new CubridDatabase[1];
cubridDatabases[0] = ERVirtualDatabase.getInstance();
}
// Limit max number one time
if (cubridDatabases.length > LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM) {
CommonUITool.openConfirmBox(Messages.bind("SchemaDesigner max...", LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM));
List<CubridDatabase> list = new ArrayList<CubridDatabase>(LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM);
for (int i = 0; i < LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM; i++) {
list.add(cubridDatabases[i]);
}
cubridDatabases = new CubridDatabase[LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM];
list.toArray(cubridDatabases);
}
for (CubridDatabase database : cubridDatabases) {
SchemaEditorInput schemaEditorInput = new SchemaEditorInput(database, (provider instanceof TreeViewer) ? (TreeViewer) provider : null);
schemaEditorInput.setDatabase(database);
DatabaseInfo dbInfo = database.getDatabaseInfo();
if (dbInfo == null) {
continue;
}
try {
window.getActivePage().openEditor(schemaEditorInput, ERSchemaEditor.ID);
if (Util.isMac()) {
// refresh for low version mac
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setEditorAreaVisible(false);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setEditorAreaVisible(true);
}
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
}
}
use of org.eclipse.ui.PartInitException in project cubrid-manager by CUBRID.
the class QueryOpenAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null || window.getActivePage() == null) {
return;
}
IEditorPart editor = window.getActivePage().getActiveEditor();
if (editor != null && editor.isDirty()) {
int confirm = CommonUITool.openMsgBox(editor.getSite().getShell(), MessageDialog.WARNING, Messages.saveResource, Messages.bind(Messages.saveConfirm, editor.getTitle()), new String[] { Messages.btnYes, Messages.btnNo, Messages.cancel });
switch(confirm) {
case 0:
editor.doSave(null);
break;
case 1:
break;
default:
return;
}
}
try {
if (editor == null) {
IEditorInput input = new QueryUnit();
editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
}
} catch (PartInitException e) {
CommonUITool.openErrorBox(e.getMessage());
}
if (editor == null) {
return;
}
try {
QueryEditorPart queryEditor = (QueryEditorPart) editor;
SQLEditorComposite editorComp = queryEditor.getCombinedQueryComposite().getSqlEditorComp();
String encoding = editorComp.getDocument().getEncoding();
SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), encoding, true);
if (IDialogConstants.OK_ID == dialog.open()) {
editorComp.open(dialog.getFilePath(), dialog.getEncoding());
}
} catch (IOException e) {
CommonUITool.openErrorBox(e.getMessage());
}
}
use of org.eclipse.ui.PartInitException in project cubrid-manager by CUBRID.
the class QueryEditorUtil method openQueryEditorAndRunQuery.
/**
* Open query editor and run query
*
* @param database
* @param query
* @param isAutoRun
* @param isOpenInExistEditor
*/
public static void openQueryEditorAndRunQuery(CubridDatabase database, String query, boolean isAutoRun, boolean isOpenInExistEditor) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
QueryEditorPart queryEditor = null;
/*Find exist query editor*/
if (isOpenInExistEditor) {
List<QueryEditorPart> editorPartList = getAllQueryEditorPart();
for (QueryEditorPart editor : editorPartList) {
if (database.equals(editor.getSelectedDatabase())) {
queryEditor = editor;
}
}
}
boolean isNewQueryEditor = false;
/*Open new query editor*/
if (queryEditor == null) {
QueryUnit input = new QueryUnit();
input.setDatabase(database);
try {
queryEditor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
queryEditor.connect(database);
isNewQueryEditor = true;
} catch (PartInitException ex) {
LOGGER.equals(ex.getMessage());
}
}
/*Run query*/
if (queryEditor != null) {
if (isNewQueryEditor) {
queryEditor.setQuery(query, false, isAutoRun, false);
} else {
queryEditor.newQueryTab(query, isAutoRun);
}
window.getActivePage().activate(queryEditor);
}
}
Aggregations