Search in sources :

Example 36 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage in project KaiZen-OpenAPI-Editor by RepreZen.

the class TextDocumentMarkerResolution method openTextEditor.

protected ITextEditor openTextEditor(IFile file) throws CoreException {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart part;
    try {
        part = IDE.openEditor(page, file, true);
    } catch (PartInitException e) {
        throw new CoreException(createStatus(e, "Cannot open editor"));
    }
    if (!(part instanceof ITextEditor)) {
        throw new CoreException(createStatus(null, "The editor is not TextEditor: " + part));
    }
    return (ITextEditor) part;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 37 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage 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 38 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage in project cubrid-manager by CUBRID.

the class TableContentProvider method close.

/**
	 * dispose
	 */
public void close() {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    ImportDataViewPart editor = (ImportDataViewPart) page.findEditor(input);
    if (editor != null) {
        page.activate(editor);
        page.closeEditor(editor, false);
    }
}
Also used : IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 39 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage in project cubrid-manager by CUBRID.

the class ExportDataViewPart method close.

/**
	 * dispose
	 */
public void close() {
    super.dispose();
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    ExportDataViewPart editor = (ExportDataViewPart) page.findEditor(input);
    if (editor != null) {
        page.activate(editor);
        page.closeEditor(editor, false);
    }
}
Also used : IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 40 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage in project cubrid-manager by CUBRID.

the class SqlmapNavigatorView method getInstance.

/**
	 * Return current SqlmapNavigatorView instance.
	 *
	 * @return
	 */
public static SqlmapNavigatorView getInstance() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }
    IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return null;
    }
    IViewReference viewReference = page.findViewReference(ID);
    if (viewReference != null) {
        IViewPart viewPart = viewReference.getView(false);
        return viewPart instanceof SqlmapNavigatorView ? (SqlmapNavigatorView) viewPart : null;
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Aggregations

IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)827 PartInitException (org.eclipse.ui.PartInitException)309 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)296 IEditorPart (org.eclipse.ui.IEditorPart)268 IFile (org.eclipse.core.resources.IFile)221 FileEditorInput (org.eclipse.ui.part.FileEditorInput)99 IViewPart (org.eclipse.ui.IViewPart)98 IWorkbench (org.eclipse.ui.IWorkbench)89 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)88 IEditorInput (org.eclipse.ui.IEditorInput)84 IEditorReference (org.eclipse.ui.IEditorReference)83 IResource (org.eclipse.core.resources.IResource)76 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)69 CoreException (org.eclipse.core.runtime.CoreException)66 ISelection (org.eclipse.jface.viewers.ISelection)64 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)60 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)59 IOException (java.io.IOException)57 ArrayList (java.util.ArrayList)56 IProject (org.eclipse.core.resources.IProject)51