Search in sources :

Example 1 with IViewReference

use of org.eclipse.ui.IViewReference 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 2 with IViewReference

use of org.eclipse.ui.IViewReference 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)

Example 3 with IViewReference

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

the class JdbcManageComposite method isJdbcDriverUsing.

/**
	 * 
	 * Return whether the JDBC driver is using
	 * 
	 * @param jdbcVersion String
	 * @return boolean
	 */
private boolean isJdbcDriverUsing(String jdbcVersion) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return false;
    }
    IViewReference[] viewReference = page.getViewReferences();
    for (int i = 0; viewReference != null && i < viewReference.length; i++) {
        IViewPart viewPart = viewReference[i].getView(false);
        if (!(viewPart instanceof CubridNavigatorView)) {
            continue;
        }
        CubridNavigatorView navigatorView = (CubridNavigatorView) viewPart;
        List<ICubridNode> list = getUsingJdbcNodeList(navigatorView);
        if (list == null) {
            continue;
        }
        for (ICubridNode node : list) {
            if (NodeType.SERVER.equals(node.getType())) {
                CubridServer server = (CubridServer) node;
                ServerInfo serverInfo = server.getServerInfo();
                if (serverInfo == null) {
                    continue;
                }
                if (serverInfo.isConnected() && serverInfo.getJdbcDriverVersion().equals(jdbcVersion)) {
                    CommonUITool.openErrorBox(Messages.bind(Messages.errDeleteJdbcServer, new Object[] { serverInfo.getServerName(), jdbcVersion }));
                    return true;
                }
            } else if (NodeType.DATABASE.equals(node.getType())) {
                CubridDatabase database = (CubridDatabase) node;
                if (database == null || database.getServer() == null || database.getServer().getServerInfo() == null) {
                    continue;
                }
                ServerInfo serverInfo = database.getServer().getServerInfo();
                if (serverInfo == null) {
                    LOGGER.error("The serverInfo is a null.");
                    return false;
                }
                boolean isSameVersion = StringUtil.isEqual(serverInfo.getJdbcDriverVersion(), jdbcVersion);
                if (isSameVersion && database.isLogined()) {
                    CommonUITool.openErrorBox(Messages.bind(Messages.errDeleteJdbcConn, new Object[] { database.getName(), jdbcVersion }));
                    return true;
                }
            }
        }
    }
    IEditorReference[] editorReference = page.getEditorReferences();
    for (int i = 0; editorReference != null && i < editorReference.length; i++) {
        IEditorPart editorPart = editorReference[i].getEditor(false);
        if (!(editorPart instanceof QueryEditorPart)) {
            continue;
        }
        QueryEditorPart queryEditorPart = (QueryEditorPart) editorPart;
        CubridServer server = queryEditorPart.getSelectedServer();
        ServerInfo serverInfo = server == null ? null : server.getServerInfo();
        String partName = queryEditorPart.getPartName();
        if (serverInfo != null && serverInfo.getJdbcDriverVersion().equals(jdbcVersion)) {
            CommonUITool.openErrorBox(Messages.bind(Messages.errDeleteJdbcQuery, new Object[] { partName, jdbcVersion }));
            return true;
        }
    }
    return false;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 4 with IViewReference

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

the class FavoriteQueryNavigatorView method getInstance.

public static FavoriteQueryNavigatorView 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 FavoriteQueryNavigatorView ? (FavoriteQueryNavigatorView) 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)

Example 5 with IViewReference

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

the class FavoriteQueryNavigatorView method setFocus.

public void setFocus() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return;
    }
    IViewReference viewReference = page.findViewReference(ID);
    if (viewReference != null) {
        IViewPart viewPart = viewReference.getView(false);
        getSite().getPage().activate(viewPart);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Aggregations

IViewReference (org.eclipse.ui.IViewReference)66 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)48 IViewPart (org.eclipse.ui.IViewPart)37 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)23 PartInitException (org.eclipse.ui.PartInitException)23 IFile (org.eclipse.core.resources.IFile)10 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)8 ArrayList (java.util.ArrayList)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)8 CubridViewPart (com.cubrid.common.ui.spi.part.CubridViewPart)7 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)7 IOException (java.io.IOException)6 IEditorInput (org.eclipse.ui.IEditorInput)6 IEditorReference (org.eclipse.ui.IEditorReference)6 HostNode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode)4 ParseException (java.text.ParseException)4 IProject (org.eclipse.core.resources.IProject)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4