Search in sources :

Example 51 with Display

use of org.eclipse.swt.widgets.Display in project ACS by ACS-Community.

the class LoadFromCDBActionDelegate method run.

@Override
public void run(IAction action) {
    if (_window == null)
        return;
    boolean confirmLoad;
    confirmLoad = MessageDialog.openQuestion(_window.getShell(), "Load from CDB", "Load contents from the CDB?");
    if (!confirmLoad)
        return;
    final Display display = _window.getShell().getDisplay();
    new Thread(new Runnable() {

        public void run() {
            display.syncExec(new Runnable() {

                public void run() {
                    // Disable all views
                    IViewReference[] views = _window.getActivePage().getViewReferences();
                    for (int i = 0; i < views.length; i++) {
                        if (views[i].getView(false) instanceof IMyViewPart)
                            ((IMyViewPart) views[i].getView(false)).setEnabled(false);
                    }
                }
            });
            // Reload information from the CDB
            AlarmSystemManager.getInstance().loadFromCDB();
            display.asyncExec(new Runnable() {

                public void run() {
                    // Enable all views, and reload their contents
                    IViewReference[] views = _window.getActivePage().getViewReferences();
                    for (int i = 0; i < views.length; i++) {
                        if (views[i].getView(false) instanceof IMyViewPart) {
                            IMyViewPart view = ((IMyViewPart) views[i].getView(false));
                            view.setEnabled(true);
                            view.refreshContents();
                        }
                    }
                }
            });
        }
    }).start();
}
Also used : IMyViewPart(cl.utfsm.acs.acg.gui.IMyViewPart) Display(org.eclipse.swt.widgets.Display)

Example 52 with Display

use of org.eclipse.swt.widgets.Display in project ACS by ACS-Community.

the class Application method stop.

public void stop() {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null)
        return;
    final Display display = workbench.getDisplay();
    display.syncExec(new Runnable() {

        public void run() {
            if (!display.isDisposed())
                workbench.close();
        }
    });
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Display(org.eclipse.swt.widgets.Display)

Example 53 with Display

use of org.eclipse.swt.widgets.Display 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 54 with Display

use of org.eclipse.swt.widgets.Display in project ACS by ACS-Community.

the class EventDetailTestHarness method main.

/**
	 * @param args
	 */
public static void main(String[] args) {
    EventModel em = null;
    try {
        em = EventModel.getInstance();
        logger = em.getLogger();
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Couldn't create the Event Model.");
        System.exit(1);
    }
    seCreator = new StructuredEventCreator(em.getContainerServices());
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    new EventDetailTestHarness(shell);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : EventModel(alma.acs.eventbrowser.model.EventModel) Shell(org.eclipse.swt.widgets.Shell) StructuredEventCreator(alma.acs.nc.StructuredEventCreator) FillLayout(org.eclipse.swt.layout.FillLayout) AcsJException(alma.acs.exceptions.AcsJException) Display(org.eclipse.swt.widgets.Display)

Example 55 with Display

use of org.eclipse.swt.widgets.Display in project ACS by ACS-Community.

the class DocumentBase method refresh.

/**
	 * Refresh the content of the table
	 */
private void refresh() {
    if (!shutdown && tableViewer != null) {
        Display display = Display.getDefault();
        display.syncExec(new Runnable() {

            public void run() {
                if (!shutdown && !tableViewer.getControl().isDisposed()) {
                    tableViewer.refresh();
                }
            }
        });
    }
}
Also used : Display(org.eclipse.swt.widgets.Display)

Aggregations

Display (org.eclipse.swt.widgets.Display)485 Shell (org.eclipse.swt.widgets.Shell)184 Point (org.eclipse.swt.graphics.Point)76 Test (org.junit.Test)63 FillLayout (org.eclipse.swt.layout.FillLayout)62 Color (org.eclipse.swt.graphics.Color)52 Button (org.eclipse.swt.widgets.Button)50 Rectangle (org.eclipse.swt.graphics.Rectangle)48 GridLayout (org.eclipse.swt.layout.GridLayout)43 Composite (org.eclipse.swt.widgets.Composite)43 GridData (org.eclipse.swt.layout.GridData)39 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)32 Image (org.eclipse.swt.graphics.Image)32 Label (org.eclipse.swt.widgets.Label)32 SWT (org.eclipse.swt.SWT)29 InvocationTargetException (java.lang.reflect.InvocationTargetException)28 StyledText (org.eclipse.swt.custom.StyledText)24 Text (org.eclipse.swt.widgets.Text)24 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)23 Font (org.eclipse.swt.graphics.Font)23