Search in sources :

Example 21 with PartInitException

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();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) UserAuthenticatorException(cl.utfsm.acs.acg.core.UserAuthenticatorException) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) UserAuthenticator(cl.utfsm.acs.acg.core.UserAuthenticator) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) Point(org.eclipse.swt.graphics.Point) PartInitException(org.eclipse.ui.PartInitException) UserAuthenticatorException(cl.utfsm.acs.acg.core.UserAuthenticatorException) IViewReference(org.eclipse.ui.IViewReference) AlarmSystemManager(cl.utfsm.acs.acg.core.AlarmSystemManager) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) Role(cl.utfsm.acs.acg.core.UserAuthenticator.Role) Display(org.eclipse.swt.widgets.Display)

Example 22 with PartInitException

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);
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 23 with PartInitException

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());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SchemaEditorInput(com.cubrid.common.ui.er.SchemaEditorInput) ArrayList(java.util.ArrayList) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 24 with PartInitException

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());
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog) IEditorInput(org.eclipse.ui.IEditorInput)

Example 25 with PartInitException

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);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

PartInitException (org.eclipse.ui.PartInitException)720 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)300 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)177 IFile (org.eclipse.core.resources.IFile)146 IEditorPart (org.eclipse.ui.IEditorPart)141 CoreException (org.eclipse.core.runtime.CoreException)94 FileEditorInput (org.eclipse.ui.part.FileEditorInput)88 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)82 IEditorInput (org.eclipse.ui.IEditorInput)74 ISelection (org.eclipse.jface.viewers.ISelection)62 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)60 IResource (org.eclipse.core.resources.IResource)59 IEditorReference (org.eclipse.ui.IEditorReference)53 IViewPart (org.eclipse.ui.IViewPart)53 IOException (java.io.IOException)42 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)41 Point (org.eclipse.swt.graphics.Point)40 IWorkbench (org.eclipse.ui.IWorkbench)40 Path (org.eclipse.core.runtime.Path)39 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)39