Example usage for org.eclipse.jface.dialogs TitleAreaDialog TitleAreaDialog

List of usage examples for org.eclipse.jface.dialogs TitleAreaDialog TitleAreaDialog

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs TitleAreaDialog TitleAreaDialog.

Prototype

public TitleAreaDialog(Shell parentShell) 

Source Link

Document

Instantiate a new title area dialog.

Usage

From source file:carisma.ui.eclipse.popup.actions.RunAnalysisAction.java

License:Open Source License

@Override
public final void run(final IAction action) {
    this.analysis = AnalysisUtil.readAnalysis(this.selectedFile.getLocation().toOSString());
    List<CheckReference> checks = this.analysis.getChecks();

    if (!checks.isEmpty()) {
        List<CheckReference> unsetRequiredParameters = this.analysis.getChecksWithInvalidParameters();
        if (unsetRequiredParameters.size() > 0) {
            showUnsetRequiredParameters(unsetRequiredParameters);
        } else {//from   w  ww.j  a  v  a2  s .  c om
            CarismaGUI.runAnalysis(this.analysis);
        }
    } else {
        Display display = Display.getDefault();
        Shell shell = new Shell(display);
        TitleAreaDialog tad = new TitleAreaDialog(shell) {
            @Override
            protected Control createDialogArea(final Composite parent) {
                setTitle("ERROR: Check list is empty!");
                PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, CarismaGUI.PLUGIN_ID + ".AdfEditor");
                setHelpAvailable(true);

                final Composite composite = (Composite) super.createDialogArea(parent);
                GridLayout compositeLayout = new GridLayout(1, false);
                compositeLayout.marginHeight = 2;
                compositeLayout.marginWidth = 10;
                composite.setLayout(compositeLayout);

                final Label label = new Label(composite, SWT.NONE);
                label.setText("There is no check in the list of the analysis.\n"
                        + "Maybe the analysis is still open and there are unsaved changes.\n \n");
                final Link link = new Link(composite, SWT.NONE);
                link.setText("Read CARiSMA <A>Help</A> for more information.");
                link.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        //                     PlatformUI.getWorkbench().getHelpSystem().displayHelpResource("/" + Carisma.PLUGIN_ID + "/help/html/maintopic.html");
                        PlatformUI.getWorkbench().getHelpSystem().displayHelp();
                        //                     PlatformUI.getWorkbench().getHelpSystem().displayHelp(Carisma.PLUGIN_ID + ".AdfEditor");
                        close();
                    }
                });
                return composite;
            }
        };
        tad.create();
        tad.open();
    }

}

From source file:com.baremetalstudios.mapleide.handlers.NewFolderDialogHandler.java

License:Open Source License

@Execute
public void openNewTextFileDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell parentShell,
        @Optional @Named(IServiceConstants.SELECTION) final IResource resource, final IWorkspace workspace,
        IProgressMonitor monitor, final Logger logger, final INLSLookupFactoryService nlsFactory) {

    TitleAreaDialog dialog = new TitleAreaDialog(parentShell) {
        private ResourceViewerControl viewer;
        private Text text;
        private Messages messages = nlsFactory.createNLSLookup(Messages.class);

        @Override/*from  w w w .jav a  2s.c  o m*/
        protected Control createDialogArea(Composite parent) {

            getShell().setText(messages.NewFolderDialogHandler_ShellTitle());
            setTitle(messages.NewFolderDialogHandler_Title());
            setMessage(messages.NewFolderDialogHandler_Message());

            Composite comp = (Composite) super.createDialogArea(parent);
            Composite container = new Composite(comp, SWT.NONE);
            container.setLayoutData(new GridData(GridData.FILL_BOTH));
            container.setLayout(new GridLayout(2, false));

            Label label = new Label(container, SWT.NONE);
            label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
            label.setText(messages.NewFolderDialogHandler_ParentFolder());

            viewer = new ResourceViewerControl(container, SWT.NONE, workspace, resource);
            viewer.setLayoutData(new GridData(GridData.FILL_BOTH));

            label = new Label(container, SWT.NONE);
            label.setText(messages.NewFolderDialogHandler_FolderName());

            text = new Text(container, SWT.BORDER);
            text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

            return comp;
        }

        @Override
        protected void okPressed() {
            IResource resource = viewer.getResource();
            if (resource == null) {
                setMessage(messages.NewFolderDialogHandler_ErrorSelectAParentFolder(), IMessageProvider.ERROR);
                return;
            }

            if (text.getText().trim().length() == 0) {
                setMessage(messages.NewFolderDialogHandler_ErrorEnterFolderName(), IMessageProvider.ERROR);
                return;
            }

            IPath newFolderPath = resource.getFullPath().append(text.getText());
            IFolder folder = workspace.getRoot().getFolder(newFolderPath);
            try {
                folder.create(false, true, null);
                super.okPressed();
            } catch (CoreException e) {
                logger.error(e);
                setMessage(messages.NewFolderDialogHandler_ErrorFolderCreation(), IMessageProvider.ERROR);
            }
        }
    };

    dialog.open();
}

From source file:com.baremetalstudios.mapleide.handlers.NewTextFileDialogHandler.java

License:Open Source License

@Execute
public void openNewTextFileDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell parentShell,
        @Optional @Named(IServiceConstants.SELECTION) final IResource resource, final IWorkspace workspace,
        IProgressMonitor monitor) {/*from   www.j av a  2  s  . co  m*/

    TitleAreaDialog dialog = new TitleAreaDialog(parentShell) {
        private ResourceViewerControl viewer;
        private Text text;

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite comp = (Composite) super.createDialogArea(parent);
            Composite container = new Composite(comp, SWT.NONE);
            container.setLayoutData(new GridData(GridData.FILL_BOTH));
            container.setLayout(new GridLayout(2, false));

            Label label = new Label(container, SWT.NONE);
            label.setText("Folder");

            viewer = new ResourceViewerControl(container, SWT.NONE, workspace, resource);
            viewer.setLayoutData(new GridData(GridData.FILL_BOTH));

            label = new Label(container, SWT.NONE);
            label.setText("File name");

            text = new Text(container, SWT.BORDER);
            text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

            return comp;
        }

        @Override
        protected void okPressed() {
            IResource resource = viewer.getResource();
            if (resource == null) {
                setMessage("Select a parent folder", IMessageProvider.ERROR);
                return;
            }

            if (text.getText().trim().length() == 0) {
                setMessage("Enter a folder name", IMessageProvider.ERROR);
                return;
            }

            parentContainer = (IContainer) resource;
            name = text.getText();
            super.okPressed();
        }
    };

    if (dialog.open() == IDialogConstants.OK_ID) {
        IPath newFilePath = parentContainer.getFullPath().append(name);
        IFile file = workspace.getRoot().getFile(newFilePath);
        ByteArrayInputStream out = new ByteArrayInputStream(new byte[0]);
        try {
            file.create(out, true, monitor);
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            out.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:com.google.gapid.widgets.AboutDialog.java

License:Apache License

public static void showAbout(Shell shell, Theme theme) {
    new TitleAreaDialog(shell) {
        @Override//from   www  . j a v a  2s  . c  om
        public void create() {
            super.create();
            setTitle(Messages.ABOUT_TITLE);
        }

        @Override
        protected void configureShell(Shell newShell) {
            super.configureShell(newShell);
            newShell.setText(Messages.ABOUT_WINDOW_TITLE);
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite area = (Composite) super.createDialogArea(parent);
            area.setBackground(theme.aboutBackground());

            Composite container = createComposite(area, centered(new RowLayout(SWT.VERTICAL)));
            container.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));

            container.setBackground(theme.aboutBackground());
            createLabel(container, "", theme.logoBig());
            Label title = createForegroundLabel(container, Messages.WINDOW_TITLE);
            title.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
            createForegroundLabel(container, "Version " + Version.GAPIC_VERSION);
            createForegroundLabel(container,
                    "Server: " + Info.getServerName() + ", Version: " + Info.getServerVersion());
            createForegroundLabel(container, Messages.ABOUT_DESCRIPTION);
            createForegroundLabel(container, Messages.ABOUT_COPY);

            return area;
        }

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
        }

        public Label createForegroundLabel(Composite parent, String text) {
            Label label = createLabel(parent, text);
            label.setForeground(theme.aboutForeground());
            label.setBackground(theme.aboutBackground());
            return label;
        }

    }.open();
}

From source file:de.hpi.sam.bp2009.solution.oclToAst.ui.OclToAstAction.java

License:Open Source License

/**
 * Show an Error window for the given parser and location
 * @param p the given EAnnotationParser, which hold all ErrorMessages
 * @param location the location of the traversed resource
 * @param last is this the last one?/*from  w ww  .  j ava 2s  .  c  o m*/
 * @return if error window was shown
 * @throws CancellationException if the user cancels the parsing
 */
private boolean showErrorMessageIfNeeded(final EAnnotationOCLParser p, final String location,
        final boolean last) throws CancellationException {
    if (p.getAllOccurredErrorMessages().size() > 0) {
        org.eclipse.jface.dialogs.TitleAreaDialog dialog = new TitleAreaDialog(new Shell()) {
            @Override
            protected Control createDialogArea(Composite parent) {
                setTitle("EAnnotation Parsing Complete");
                if (last) {
                    setErrorMessage("Error occured during parsing of " + location);
                } else {
                    setErrorMessage("Error occured during parsing of " + location
                            + "\n Should the parsing process continue?");

                }
                Composite par = (Composite) super.createDialogArea(parent);
                GridLayout lay = new GridLayout(3, false);
                par.setLayout(lay);
                parent.setSize(400, 400);
                /*
                 * remove standard line
                 */
                par.getChildren()[0].dispose();
                for (ErrorMessage e : p.getAllOccurredErrorMessages()) {
                    Text l = new Text(par, SWT.READ_ONLY | SWT.WRAP);
                    GridData g = new GridData(SWT.BORDER);
                    g.widthHint = 200;
                    l.setLayoutData(g);
                    if (e.getMessageString() != null)
                        l.setText(e.getMessageString());
                    Text l1 = new Text(par, SWT.READ_ONLY | SWT.WRAP);
                    GridData g1 = new GridData(SWT.BORDER);
                    g1.widthHint = 200;
                    l1.setLayoutData(g1);
                    if (e.getException() != null)
                        l1.setText(e.getException().toString());
                    Text l2 = new Text(par, SWT.READ_ONLY | SWT.WRAP);
                    GridData g2 = new GridData(SWT.BORDER);
                    g2.widthHint = 200;
                    l2.setLayoutData(g2);
                    if (e.getAffectedObject() != null)
                        l2.setText(e.getAffectedObject().toString());

                }
                p.getAllOccurredErrorMessages().clear();
                setDialogHelpAvailable(false);
                par.update();
                return par;
            }

        };
        if (dialog.open() == Dialog.ABORT)
            throw new CancellationException("User canceled parsing");
        return false;
    } else {
        return true;
    }
}

From source file:org.baz.desktop.randomapp.RandomApp.java

License:Creative Commons License

public RandomApp() {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1, false));
    shell.setText("Random app");

    /* This is just to show that JFace works */
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Open JFace Dialog");
    button.addListener(SWT.Selection, new Listener() {
        @Override/* w w  w  . j a  v  a 2s  .  co m*/
        public void handleEvent(Event arg0) {
            new TitleAreaDialog(shell).open();
        }
    });

    shell.pack();
    shell.setSize(400, 300);
    shell.open();

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

    display.dispose();
}

From source file:org.eclipse.e4.demo.simpleide.handlers.NewProjectDialogHandler.java

License:Open Source License

@Execute
public void openNewProjectDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell parentShell, IWorkspace workspace,
        IProgressMonitor monitor, final ServiceRegistryComponent serviceRegistry, StatusReporter reporter,
        Logger logger, final INLSLookupFactoryService nlsFactory) {

    TitleAreaDialog dialog = new TitleAreaDialog(parentShell) {
        private Text projectName;
        private TableViewer projectType;
        private Messages messages = nlsFactory.createNLSLookup(Messages.class);

        @Override/*from www . j av  a2 s.c o m*/
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite comp = (Composite) super.createDialogArea(parent);
            getShell().setText(messages.NewProjectDialogHandler_ShellTitle());
            setTitle(messages.NewProjectDialogHandler_Title());
            setMessage(messages.NewProjectDialogHandler_Message());

            final Image titleImage = new Image(parent.getDisplay(),
                    getClass().getClassLoader().getResourceAsStream("/icons/wizard/newprj_wiz.png"));

            setTitleImage(titleImage);

            final Image shellImg = new Image(parent.getDisplay(),
                    getClass().getClassLoader().getResourceAsStream("/icons/newprj_wiz.gif"));
            getShell().setImage(shellImg);
            getShell().addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    shellImg.dispose();
                    titleImage.dispose();
                }
            });

            Composite container = new Composite(comp, SWT.NONE);
            container.setLayoutData(new GridData(GridData.FILL_BOTH));
            container.setLayout(new GridLayout(2, false));

            Label l = new Label(container, SWT.NONE);
            l.setText(messages.NewProjectDialogHandler_Name());

            projectName = new Text(container, SWT.BORDER);
            projectName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

            l = new Label(container, SWT.NONE);
            l.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
            l.setText(messages.NewProjectDialogHandler_Type());

            projectType = new TableViewer(container);
            projectType.setContentProvider(new ArrayContentProvider());
            projectType.setLabelProvider(new LabelProvider() {
                @Override
                public String getText(Object element) {
                    IProjectService el = (IProjectService) element;
                    return el.getLabel();
                }

                @Override
                public Image getImage(Object element) {
                    IProjectService el = (IProjectService) element;
                    Image img = images.get(el);
                    if (img == null) {
                        URL url;
                        InputStream in = null;
                        try {
                            url = FileLocator.find(new URL(el.getIconURI()));
                            in = url.openStream();
                            img = new Image(getShell().getDisplay(), in);
                            images.put(el, img);
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } finally {
                            if (in != null) {
                                try {
                                    in.close();
                                } catch (IOException e) {
                                }
                            }
                        }
                    }
                    return img;
                }
            });

            Vector<IProjectService> creators = serviceRegistry.getCreators();
            projectType.setInput(creators);
            if (creators.size() > 0) {
                projectType.setSelection(new StructuredSelection(creators.get(0)));
            }
            projectType.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

            getShell().addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    for (Image img : images.values()) {
                        img.dispose();
                    }
                    images.clear();
                }
            });

            return comp;
        }

        @Override
        protected void okPressed() {
            if (projectType.getSelection().isEmpty()) {
                setMessage("Please select a project type", IMessageProvider.ERROR);
                return;
            }

            if (projectName.getText().trim().length() == 0) {
                setMessage("Please enter a projectname", IMessageProvider.ERROR);
                return;
            }

            NewProjectDialogHandler.this.creator = (IProjectService) ((IStructuredSelection) projectType
                    .getSelection()).getFirstElement();
            NewProjectDialogHandler.this.projectName = projectName.getText();

            super.okPressed();
        }
    };

    if (dialog.open() == IDialogConstants.OK_ID) {
        creator.createProject(parentShell, workspace, reporter, logger, monitor, projectName);
    }
}

From source file:org.eclipse.e4.tools.emf.ui.script.js.JavaScriptSupport.java

License:Open Source License

public void openEditor(Shell shell, final Object mainElement, final IEclipseContext context) {
    final IEclipseContext childContext = context.createChild();

    TitleAreaDialog dialog = new TitleAreaDialog(shell) {
        private JavaScriptEditor editor;
        private Logger logger;

        @Override//from   w  w  w .j  a  v  a 2s  .c om
        protected Control createDialogArea(Composite parent) {
            Composite container = (Composite) super.createDialogArea(parent);
            logger = new Logger(getShell());
            getShell().setText("Execute JavaScript");
            setTitle("Execute JavaScript");
            setMessage("Enter some JavaScript and execute it");
            setTitleImage(childContext.get(IResourcePool.class)
                    .getImageUnchecked(ResourceProvider.IMG_WIZBAN_JAVASCRIPT));

            childContext.set(Composite.class, container);

            editor = ContextInjectionFactory.make(JavaScriptEditor.class, childContext);
            GridData gd = new GridData(GridData.FILL_BOTH);
            gd.minimumHeight = 350;
            gd.minimumWidth = 400;
            editor.getControl().setLayoutData(gd);
            return container;
        }

        @Override
        protected void okPressed() {
            execute(logger, mainElement, context, editor.getContent());
        }

        @Override
        protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
            return super.createButton(parent, id, id == IDialogConstants.OK_ID ? "Execute" : label,
                    defaultButton);
        }
    };

    dialog.open();
    childContext.dispose();
}

From source file:org.eclipse.e4.tools.ui.designer.wizards.part.NewOptionsPartWizardPage.java

License:Open Source License

protected void handleDataContextProperties() {
    TitleAreaDialog dialog = new TitleAreaDialog(getShell()) {

        public void create() {
            setShellStyle(getShellStyle() | SWT.RESIZE);
            super.create();
        }//  www .ja v a2 s . c  om

        protected Control createDialogArea(Composite parent) {
            Composite control = (Composite) super.createDialogArea(parent);
            Composite newControl = new Composite(control, SWT.NONE);
            newControl.setLayoutData(new GridData(GridData.FILL_BOTH));
            newControl.setLayout(new GridLayout());
            Composite composite = PropertiesComposite.create(newControl, dataContext);
            composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
            return control;
        }

        protected void createButtonsForButtonBar(Composite parent) {
            createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
        }
    };
    dialog.create();
    dialog.setTitle("Properties");
    dialog.getShell().setText("Properties Configure Dialog");
    dialog.setMessage("Configure properties and master value.");
    dialog.open();
}

From source file:org.eclipse.equinox.p2.ui.ProvisioningUI.java

License:Open Source License

/**
 * Open a UI that allows the user to manipulate the repositories.
 * @param shell the shell that should parent the UI
 *//*from   ww  w  .  jav  a 2  s. co m*/
public void manipulateRepositories(Shell shell) {
    if (policy.getRepositoryPreferencePageId() != null) {
        PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell,
                policy.getRepositoryPreferencePageId(), null, null);
        dialog.open();
    } else {
        TitleAreaDialog dialog = new TitleAreaDialog(shell) {
            RepositoryManipulationPage page;

            protected Control createDialogArea(Composite parent) {
                page = new RepositoryManipulationPage();
                page.setProvisioningUI(ProvisioningUI.this);
                page.init(PlatformUI.getWorkbench());
                page.createControl(parent);
                this.setTitle(ProvUIMessages.RepositoryManipulationPage_Title);
                this.setMessage(ProvUIMessages.RepositoryManipulationPage_Description);

                Control control = page.getControl();
                control.setLayoutData(new GridData(GridData.FILL_BOTH));
                return page.getControl();
            }

            protected boolean isResizable() {
                return true;
            }

            protected void okPressed() {
                if (page.performOk())
                    super.okPressed();
            }

            protected void cancelPressed() {
                if (page.performCancel())
                    super.cancelPressed();
            }
        };
        dialog.open();
    }
}