Example usage for org.eclipse.jface.databinding.swt SWTObservables getRealm

List of usage examples for org.eclipse.jface.databinding.swt SWTObservables getRealm

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt SWTObservables getRealm.

Prototype

@Deprecated
public static Realm getRealm(final Display display) 

Source Link

Document

Returns the realm representing the UI thread for the given display.

Usage

From source file:de.prozesskraft.pradar.parts.PradarPartUi3.java

/**
 * @param args//from   w  ww  .ja  v  a  2  s . c  om
 */
public static void main(String[] args) {
    /*----------------------------
      get options from ini-file
    ----------------------------*/
    File inifile = new java.io.File(
            WhereAmI.getInstallDirectoryAbsolutePath(PradarPartUi3.class) + "/" + "../etc/pradar-gui.ini");

    if (inifile.exists()) {
        try {
            ini = new Ini(inifile);
        } catch (InvalidFileFormatException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else {
        System.err.println("ini file does not exist: " + inifile.getAbsolutePath());
        System.exit(1);
    }

    /*----------------------------
      create boolean options
    ----------------------------*/
    Option help = new Option("help", "print this message");
    Option v = new Option("v", "prints version and build-date");
    /*----------------------------
      create argument options
    ----------------------------*/
    Option dbfile = OptionBuilder.withArgName("dbfile").hasArg().withDescription("[optional] dbfile")
            //            .isRequired()
            .create("dbfile");
    /*----------------------------
      create options object
    ----------------------------*/
    Options options = new Options();

    options.addOption(help);
    options.addOption(v);
    options.addOption(dbfile);

    /*----------------------------
      create the parser
    ----------------------------*/
    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (Exception exp) {
        // oops, something went wrong
        System.err.println("Parsing failed. Reason: " + exp.getMessage());
    }

    /*----------------------------
      usage/help
    ----------------------------*/
    if (line.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        //         formatter.printHelp("checkin --version [% version %]", options);
        formatter.printHelp("pradar-gui", options);
        System.exit(0);
    }

    if (line.hasOption("v")) {
        System.out.println("author:  alexander.vogel@caegroup.de");
        System.out.println("version: [% version %]");
        System.out.println("date:    [% date %]");
        System.exit(0);
    }

    /*----------------------------
      die lizenz ueberpruefen und ggf abbrechen
    ----------------------------*/

    // check for valid license
    ArrayList<String> allPortAtHost = new ArrayList<String>();
    allPortAtHost.add(ini.get("license-server", "license-server-1"));
    allPortAtHost.add(ini.get("license-server", "license-server-2"));
    allPortAtHost.add(ini.get("license-server", "license-server-3"));

    MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1");

    // lizenz-logging ausgeben
    for (String actLine : (ArrayList<String>) lic.getLog()) {
        System.err.println(actLine);
    }

    // abbruch, wenn lizenz nicht valide
    if (!lic.isValid()) {
        System.exit(1);
    }

    /*----------------------------
      other things
    ----------------------------*/

    // gui
    final Display display = new Display();

    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            try {
                Shell shell = new Shell(display);
                shell.setText("pradar " + "[% version %]");

                // set an icon
                if (this.getClass().getResourceAsStream("/logoSymbol50Transp.png") != null) {
                    shell.setImage(
                            new Image(display, this.getClass().getResourceAsStream("/logoSymbol50Transp.png")));
                } else if ((new java.io.File("logoSymbol50Transp.png")).exists()) {
                    shell.setImage(new Image(display, "logoSymbol50Transp.png"));
                }

                shell.setLayout(new FillLayout());
                //               shell.setSize(1500, 1000);
                shell.setMaximized(true);
                Composite composite = new Composite(shell, SWT.NO_FOCUS);
                GridLayout gl_composite = new GridLayout(2, false);
                gl_composite.marginWidth = 0;
                gl_composite.marginHeight = 0;
                new PradarPartUi3(composite);

                try {
                    shell.open();

                    while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                            display.sleep();
                        }
                    }

                } finally {
                    if (!shell.isDisposed()) {
                        shell.dispose();
                    }
                }

            } finally {
                display.dispose();
            }
        }
    });
    System.exit(0);
}

From source file:de.prozesskraft.pramp.parts.PrampPartUi1.java

/**
 * @param args//from  w  ww  . ja v a 2  s.  co  m
 */
public static void main(String[] args) {
    /*----------------------------
      get options from ini-file
    ----------------------------*/
    File inifile = new java.io.File(
            WhereAmI.getInstallDirectoryAbsolutePath(PrampPartUi1.class) + "/" + "../etc/pramp-gui.ini");

    if (inifile.exists()) {
        try {
            ini = new Ini(inifile);
        } catch (InvalidFileFormatException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else {
        System.err.println("ini file does not exist: " + inifile.getAbsolutePath());
        System.exit(1);
    }

    /*----------------------------
      create boolean options
    ----------------------------*/
    Option help = new Option("help", "print this message");
    Option v = new Option("v", "prints version and build-date");
    /*----------------------------
      create argument options
    ----------------------------*/
    Option dbfile = OptionBuilder.withArgName("dbfile").hasArg().withDescription("[optional] dbfile")
            //            .isRequired()
            .create("dbfile");
    /*----------------------------
      create options object
    ----------------------------*/
    Options options = new Options();

    options.addOption(help);
    options.addOption(v);
    options.addOption(dbfile);

    /*----------------------------
      create the parser
    ----------------------------*/
    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (Exception exp) {
        // oops, something went wrong
        System.err.println("Parsing failed. Reason: " + exp.getMessage());
    }

    /*----------------------------
      usage/help
    ----------------------------*/
    if (line.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        //         formatter.printHelp("checkin --version [% version %]", options);
        formatter.printHelp("pramp-gui", options);
        System.exit(0);
    }

    if (line.hasOption("v")) {
        System.out.println("author:  alexander.vogel@caegroup.de");
        System.out.println("version: [% version %]");
        System.out.println("date:    [% date %]");
        System.exit(0);
    }

    /*----------------------------
      die lizenz ueberpruefen und ggf abbrechen
    ----------------------------*/

    // check for valid license
    ArrayList<String> allPortAtHost = new ArrayList<String>();
    allPortAtHost.add(ini.get("license-server", "license-server-1"));
    allPortAtHost.add(ini.get("license-server", "license-server-2"));
    allPortAtHost.add(ini.get("license-server", "license-server-3"));

    MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1");

    // lizenz-logging ausgeben
    for (String actLine : (ArrayList<String>) lic.getLog()) {
        System.err.println(actLine);
    }

    // abbruch, wenn lizenz nicht valide
    if (!lic.isValid()) {
        System.exit(1);
    }

    // gui
    final Display display = new Display();

    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            try {
                shell = new Shell(display);
                shell.setText("pramp " + "[% version %]");

                // set an icon
                if (this.getClass().getResourceAsStream("/logoSymbol50Transp.png") != null) {
                    shell.setImage(
                            new Image(display, this.getClass().getResourceAsStream("/logoSymbol50Transp.png")));
                } else if ((new java.io.File("logoSymbol50Transp.png")).exists()) {
                    shell.setImage(new Image(display, "logoSymbol50Transp.png"));
                }

                shell.setLayout(new FillLayout());
                shell.setSize(1000, 780);
                Composite composite = new Composite(shell, SWT.NO_FOCUS);
                GridLayout gl_composite = new GridLayout(2, false);
                gl_composite.marginWidth = 0;
                gl_composite.marginHeight = 0;
                new PrampPartUi1(composite);

                try {
                    shell.open();

                    while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                            display.sleep();
                        }
                    }

                } finally {
                    if (!shell.isDisposed()) {
                        shell.dispose();
                    }
                }

            } finally {
                display.dispose();
            }
        }
    });
    System.exit(0);
}

From source file:de.uniluebeck.itm.spyglass.gui.configuration.AbstractDatabindingPreferencePage.java

License:Open Source License

protected final Realm getRealm() {
    return SWTObservables.getRealm(getControl().getDisplay());
}

From source file:de.uniluebeck.itm.spyglass.gui.SelectPacketSourceDialog.java

License:Open Source License

@Override
protected Control createDialogArea(final Composite parent) {
    startArea = new Composite(parent, SWT.NONE);
    final FillLayout thisLayout = new FillLayout(org.eclipse.swt.SWT.HORIZONTAL);
    startArea.setLayout(thisLayout);/*from ww w  .  j  a  v  a  2  s .co  m*/
    final GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    startArea.setLayoutData(gridData);

    final Group group1 = new Group(startArea, SWT.NONE);
    final GridLayout group1Layout = new GridLayout();
    group1Layout.makeColumnsEqualWidth = false;
    group1Layout.numColumns = 3;
    group1.setLayout(group1Layout);
    group1.setText("Sources");

    buttoniShell = new Button(group1, SWT.RADIO);
    buttoniShell.setText("iShell");

    new Label(group1, SWT.NONE);
    new Label(group1, SWT.NONE);

    buttonWiseBed = new Button(group1, SWT.RADIO);
    buttonWiseBed.setText("Testbed");

    new Label(group1, SWT.NONE);
    new Label(group1, SWT.NONE);

    buttonFile = new Button(group1, SWT.RADIO);
    buttonFile.setText("File");

    // disable the button if we're running standalone
    if (!SpyglassEnvironment.isIshellPlugin()) {
        buttoniShell.setEnabled(false);
    }

    final Composite wrapper = new Composite(group1, SWT.BORDER);
    wrapper.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    textPath2File = new Text(wrapper, SWT.BORDER);
    textPath2File.setEditable(false);
    final GC gc = new GC(textPath2File);
    final FontMetrics fm = gc.getFontMetrics();
    final int width = 60 * fm.getAverageCharWidth();
    final int height = fm.getHeight();
    gc.dispose();
    textPath2File.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false));
    textPath2File.setSize(textPath2File.computeSize(width, height));

    buttonOpenFileDialog = new Button(group1, SWT.NONE);
    buttonOpenFileDialog.setText("...");
    buttonOpenFileDialog.addListener(SWT.Selection, new Listener() {
        @SuppressWarnings("synthetic-access")
        public void handleEvent(final Event event) {
            final FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
            fd.setFilterExtensions(new String[] { "*.rec" });
            fd.setFilterPath(new File(defaultDir).getAbsoluteFile().toString());
            final String path = fd.open();
            if (path != null) {
                textPath2File.setText(path);
            }
        }
    });

    // set up data-binding
    {

        myvalues.setUseIShell(!(spyglass.getPacketReader().getSourceType().equals(SOURCE_TYPE.FILE)));
        final DataBindingContext dbc = new DataBindingContext(
                SWTObservables.getRealm(getParentShell().getDisplay()));

        // binding of select button to use a file and text file with its path
        dbc.bindValue(SWTObservables.observeSelection(buttonFile), SWTObservables.observeEnabled(textPath2File),
                null, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));

        // binding of select button to use a file and open a file selection dialog
        dbc.bindValue(SWTObservables.observeSelection(buttonFile),
                SWTObservables.observeEnabled(buttonOpenFileDialog), null,
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));

        // binding of select button to use a file and the select button to use iShell
        dbc.bindValue(SWTObservables.observeSelection(buttonFile),
                SWTObservables.observeSelection(buttoniShell),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                        .setConverter(new BooleanInversionConverter()),
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                        .setConverter(new BooleanInversionConverter()));

        // bind the button to select iShell to the corresponding property
        final IObservableValue modelObservableIsIshell = BeansObservables.observeValue(dbc.getValidationRealm(),
                myvalues, "useIShell");
        final IObservableValue modelObservableIsTestbed = BeansObservables
                .observeValue(dbc.getValidationRealm(), myvalues, "useTestbed");
        dbc.bindValue(SWTObservables.observeSelection(buttoniShell), modelObservableIsIshell, null, null);
        dbc.bindValue(SWTObservables.observeSelection(buttonWiseBed), modelObservableIsTestbed, null, null);

        // binding of the text field which contains the path to the file to the corresponding
        // string value
        final IObservableValue modelObservable1 = BeansObservables.observeValue(dbc.getValidationRealm(),
                myvalues, "path2File");
        dbc.bindValue(SWTObservables.observeText(textPath2File, SWT.Modify), modelObservable1, null, null);
    }
    initializeValues();
    group1.pack();
    startArea.pack();
    return startArea;
}

From source file:de.walware.ecommons.databinding.jface.AbstractSWTObservableValue.java

License:Open Source License

/**
 * Standard constructor for an SWT ObservableValue.  Makes sure that
 * the observable gets disposed when the SWT widget is disposed.
 * //w  w w.j  a  v  a 2  s .c  o  m
 * @param widget
 */
protected AbstractSWTObservableValue(final Widget widget) {
    this(SWTObservables.getRealm(widget.getDisplay()), widget);
}

From source file:es.cv.gvcase.fefem.common.databinding.CDateTimeObservableValue.java

License:Open Source License

/**
 * Instantiates a new c date time observable value.
 * /*from  ww  w.  j a v a 2s.  c o  m*/
 * @param cDateTime
 *            the c date time
 */
public CDateTimeObservableValue(CDateTime cDateTime) {
    super(SWTObservables.getRealm(cDateTime.getDisplay()));
    this.cDateTime = cDateTime;
    currentSelection = cDateTime.getSelection();

    cDateTime.addDisposeListener(disposeListener);
    cDateTime.addListener(SWT.Modify, updateListener);
}

From source file:gov.nasa.arc.spife.ui.timeline.TimelineViewer.java

License:Open Source License

public void setTreeTimelineContentProvider(TreeTimelineContentProvider newContentProvider) {
    TreeTimelineContentProvider oldContentProvider = getTreeTimelineContentProvider();
    if (oldContentProvider != null) {
        oldContentProvider.dispose();//from www . j  av  a2  s .  co  m
    }
    if (newContentProvider != null) {
        newContentProvider.activate();
        if (timeline != null) {
            Control control = timeline.getControl();
            if (control != null) {
                Display display = control.getDisplay();
                Realm realm = SWTObservables.getRealm(display);
                newContentProvider.setRealm(realm);
            }
        }
    }
    setProperty(CONTENT_PROVIDER, newContentProvider);
}

From source file:gov.nasa.arc.spife.ui.timeline.TimelineViewer.java

License:Open Source License

@Override
public Control createControl(final Composite parent) {
    TransferDropTargetListener.addDropSupport(this);

    if (showToolbar) {
        toolbarComposite = buildToolBarComposite(parent);
        TimelineLayoutData data = new TimelineLayoutData();
        data.preferredSize = new Point(SWT.DEFAULT, 20);
        toolbarComposite.setLayoutData(data);
        toolbarComposite.addMouseListener(toolbarMouseListener);
    }//  w ww  . ja v  a 2  s  .c  o  m
    TimelineRootEditPart rootEditPart = getRootEditPart();
    final IFigure figure = rootEditPart.getFigure();
    figure.addLayoutListener(new LayoutListener.Stub() {
        @Override
        public void postLayout(IFigure container) {
            final Control control = getControl();
            WidgetUtils.runLaterInDisplayThread(control, new Runnable() {
                @Override
                public void run() {
                    Dimension preferredSize = figure.getPreferredSize();
                    Point controlSize = control.getSize();
                    if (preferredSize.height != controlSize.y) {
                        parent.layout(true);
                    }
                }
            });
        }
    });

    Canvas canvas = new TimelineCanvas(parent);
    Control control = this.getControl();
    if (control == null) {
        setControl(canvas);
    } else {
        LogUtil.warn("Trying to set the control but the control is already set.");
    }

    MenuManager menuProvider = new EnsembleContextMenuProvider(this);
    menuProvider.setRemoveAllWhenShown(true);
    IMenuListener listener = new IMenuListener() {
        @Override
        public void menuAboutToShow(IMenuManager m) {
            boolean isSectionFrozen = isTimelineSectionFrozen();
            if (isSectionFrozen) {
                // Remove Top Freeze Section
                m.add(new RemoveFreezeSectionAction(getTimeline(), "R&emove Frozen Section",
                        getTimelineSectionModel()));
            } else {
                // Top Freeze Section
                m.add(new FreezeSectionAction(getTimeline(), "&Freeze Section", getTimelineSectionModel()));
            }
        }
    };
    menuProvider.addMenuListener(listener);
    setContextMenu(menuProvider);
    IWorkbenchPartSite site = getSite();
    if (site instanceof IEditorSite) {
        // allow extensions to the context menu but not those based on the editor input
        ((IEditorSite) site).registerContextMenu(menuProvider, getSite().getSelectionProvider(), false);
    }
    TreeTimelineContentProvider cp = getTreeTimelineContentProvider();
    if (cp != null) {
        Display display = canvas.getDisplay();
        Realm realm = SWTObservables.getRealm(display);
        cp.setRealm(realm);
    }
    return canvas;
}

From source file:madcow.magic.ui.MagicApplication.java

License:Open Source License

@Override
public Object start(IApplicationContext context) throws Exception {
    Display display = PlatformUI.createDisplay();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            try {
                MagicApplicationGUI window = new MagicApplicationGUI();
                window.open();//from   ww  w. ja  v a  2 s .c o  m
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    return 0;

}

From source file:main.java.miro.browser.conf.entrypoints.BrowserEntryPoint.java

License:Open Source License

@Override
protected void createContents(Composite parent) {
    Realm.runWithDefault(SWTObservables.getRealm(parent.getDisplay()), new BrowserRunnable(parent));
}