Example usage for org.eclipse.jdt.core IPackageFragment getElementName

List of usage examples for org.eclipse.jdt.core IPackageFragment getElementName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragment getElementName.

Prototype

@Override
String getElementName();

Source Link

Document

Returns the dot-separated package name of this fragment, for example "java.lang", or "" (the empty string), for the default package.

Usage

From source file:ar.com.fluxit.jqa.utils.JdtUtils.java

License:Open Source License

private static Collection<CommonDescriptor> collectCommonTypes(IPackageFragment packageFragment) {
    try {//from   ww w . j ava  2 s.  c  om
        Collection<CommonDescriptor> result = new ArrayList<CommonDescriptor>();
        ICompilationUnit[] compilationUnits = packageFragment.getCompilationUnits();
        for (ICompilationUnit compilationUnit : compilationUnits) {
            for (CommonDescriptor commonType : JdtUtils.collectCommonTypes(compilationUnit)) {
                if (check(commonType, packageFragment.getElementName())) {
                    result.add(commonType);
                }
            }
        }
        return result;
    } catch (JavaModelException e) {
        throw new IllegalStateException("Error while processing common types", e);
    }
}

From source file:ar.com.fluxit.jqa.utils.JdtUtils.java

License:Open Source License

private static Collection<IPackageFragment> getPackages(String pkg, IProject[] targetProjects) {
    try {/*from  w  w  w . jav  a 2 s .com*/
        Collection<IPackageFragment> result = new ArrayList<IPackageFragment>();
        for (IProject project : targetProjects) {
            IJavaProject javaProject = JavaCore.create(project);
            for (IPackageFragment packageFragment : javaProject.getPackageFragments()) {
                if (packageFragment.getElementName().equals(pkg) && JdtUtils.isSourcePackage(packageFragment)) {
                    result.add(packageFragment);
                }
            }
        }
        return result;
    } catch (JavaModelException e) {
        throw new IllegalStateException("An error occured while collecting packages", e);
    }
}

From source file:ar.com.tadp.xml.rinzo.jdt.wizards.NewJAXBParserWizard.java

License:Open Source License

private void createParser() throws JavaModelException {
    RootTypeFactoryMethod rootType = this.getRootType();
    String className = rootType.getRootType() + "Parser.java";

    IPackageFragment packageFragment = this.newParserPage.getPackageFragmentRoot()
            .getPackageFragment(this.newParserPage.getPackage());

    String source = this.getParserSourceCode(packageFragment.getElementName(), rootType.getMethodName(),
            rootType.getRootType());/* w  w w.  ja v  a  2  s  .com*/

    packageFragment.createCompilationUnit(className, source, false, null);
}

From source file:ar.com.tadp.xml.rinzo.jdt.wizards.NewPackageContainerWizardPage.java

License:Open Source License

private void typePageChangeControlPressed(DialogField field) {
    if (field == packageDialogField) {
        IPackageFragment pack = choosePackage();
        if (pack != null) {
            packageDialogField.setText(pack.getElementName());
        }/*  w  w w.  j a  va 2s .c o m*/
    }
}

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.AddFontDialog.java

License:Open Source License

@Override
protected Control createDialogContent(Composite parent) {
    o = ParametersFactory.eINSTANCE.createKeyValuePair();
    Composite area = new Composite(parent, SWT.NONE);
    area.setLayout(new GridLayout(1, false));
    area.setLayoutData(new GridData(GridData.FILL_BOTH));

    getShell().setText("Add font ");
    setTitle("Add font");
    setMessage("Enter informations about the font to add");

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

    IWidgetValueProperty tProp = WidgetProperties.text(SWT.Modify);

    {//from  w w w . j a v  a2s  . com
        Label l = new Label(container, SWT.NONE);
        l.setText("Font name*:");
        tFontName = new Text(container, SWT.BORDER);
        GridData tFontGD = new GridData(GridData.FILL_HORIZONTAL);
        tFontGD.horizontalSpan = 2;
        tFontName.setLayoutData(tFontGD);
        IEMFValueProperty prop = EMFEditProperties.value(editingDomain, KEY_VALUE_PAIR__KEY);
        dbContext.bindValue(tProp.observeDelayed(DELAY, tFontName), prop.observe(o),
                new EMFUpdateValueStrategy(EMFUpdateValueStrategy.POLICY_ON_REQUEST),
                new EMFUpdateValueStrategy());
    }

    {
        Label l = new Label(container, SWT.NONE);
        l.setText("File*:");

        tFile = new Text(container, SWT.BORDER);
        tFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        tFile.setEditable(false);
        IEMFValueProperty prop = EMFEditProperties.value(editingDomain, KEY_VALUE_PAIR__VALUE);
        dbContext.bindValue(tProp.observeDelayed(DELAY, tFile), prop.observe(o),
                new EMFUpdateValueStrategy(EMFUpdateValueStrategy.POLICY_ON_REQUEST),
                new EMFUpdateValueStrategy());
        Button b = new Button(container, SWT.NONE);
        b.setText("Browse ...");
        b.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent e) {
                FilteredResourcesSelectionDialog d = new FilteredResourcesSelectionDialog(getShell(), false,
                        resourceContainer, IResource.FILE) {
                    @Override
                    protected IStatus validateItem(final Object item) {
                        IFile f = (IFile) item;
                        if (f.getParent() instanceof IProject) {
                            return new Status(IStatus.ERROR, JavaFXUIPlugin.PLUGIN_ID,
                                    "The selected resource has to be part of the source folder");
                        }
                        if (!f.getName().endsWith(".ttf")) {
                            return new Status(IStatus.ERROR, JavaFXUIPlugin.PLUGIN_ID,
                                    "The selected resource does not seem to be a font");
                        }
                        return super.validateItem(item);
                    }
                };

                if (d.open() == ResourceSelectionDialog.OK) {
                    Object[] rv = d.getResult();
                    if (rv.length == 1) {
                        IFile f = (IFile) rv[0];
                        IJavaElement j = JavaCore.create(f.getParent());
                        if (j instanceof IPackageFragment) {
                            IPackageFragment p = (IPackageFragment) j;
                            tFile.setText(p.getElementName().replace('.', '/') + "/" + f.getName());
                        } else if (j instanceof IPackageFragmentRoot) {
                            IPackageFragmentRoot p = (IPackageFragmentRoot) j;
                            tFile.setText(f.getName());
                        } else {
                            MessageDialog.openInformation(getShell(), "Not valid",
                                    "The selected resource has to be part of the source folder");
                        }
                    }
                }
            }
        });

    }
    return area;
}

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.JFXBuildConfigurationEditor.java

License:Open Source License

private void createPageDeploy(final AntTask task) {
    Composite composite = new Composite(getContainer(), SWT.NONE);
    FillLayout layout = new FillLayout();
    composite.setLayout(layout);/* ww  w  . jav a 2  s  .c om*/
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
            JavaFXUIPlugin.PLUGIN_ID + ".JFXBuildConfigurationEditor_deploy");

    // TODO
    final WritableValue bean = new WritableValue();
    bean.setValue(task);

    toolkit = new FormToolkit(composite.getDisplay());

    final Form form = toolkit.createForm(composite);
    form.setText("FX Build Configuration");
    form.setImage(getTitleImage());
    form.getBody().setLayout(new FillLayout());
    toolkit.decorateFormHeading(form);

    initToolbar(form);

    ScrolledForm scrolledForm = toolkit.createScrolledForm(form.getBody());
    scrolledForm.getBody().setLayout(new GridLayout(2, false));
    Composite sectionParent = scrolledForm.getBody();

    dbc = new DataBindingContext();
    IWidgetValueProperty textModify = WidgetProperties.text(SWT.Modify);
    IWidgetValueProperty selChange = WidgetProperties.selection();

    {
        Section section = toolkit.createSection(sectionParent,
                Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
        section.setText("Deploy Properties");
        section.setDescription("The following properties are needed to create a Java Webstart Deployment");
        section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        Composite sectionClient = toolkit.createComposite(section);
        final int COLUMN_COUNT = 3;
        sectionClient.setLayout(new GridLayout(COLUMN_COUNT, false));

        {
            toolkit.createLabel(sectionClient, "Applet Width*:");
            Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = COLUMN_COUNT - 1;
            t.setLayoutData(gd);
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__WIDTH));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Applet Height*:");
            Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = COLUMN_COUNT - 1;
            t.setLayoutData(gd);
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__HEIGHT));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            Button b = toolkit.createButton(sectionClient, "Embed JNLP", SWT.CHECK);
            b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, COLUMN_COUNT, 1));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__EMBEDJNLP));
            dbc.bindValue(selChange.observe(b), prop.observeDetail(bean));
        }

        {
            Button b = toolkit.createButton(sectionClient, "Treat files as extensions", SWT.CHECK);
            b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, COLUMN_COUNT, 1));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__EXTENSION));
            dbc.bindValue(selChange.observe(b), prop.observeDetail(bean));
        }

        {
            Button b = toolkit.createButton(sectionClient, "Include deployment toolkit", SWT.CHECK);
            b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, COLUMN_COUNT, 1));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__INCLUDE_DT));
            dbc.bindValue(selChange.observe(b), prop.observeDetail(bean));
        }

        {
            Button b = toolkit.createButton(sectionClient, "Native Package", SWT.CHECK);
            b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, COLUMN_COUNT, 1));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__NATIVE_PACKAGE));
            dbc.bindValue(selChange.observe(b), prop.observeDetail(bean));
        }

        {
            Button b = toolkit.createButton(sectionClient, "Offline allowed", SWT.CHECK);
            b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, COLUMN_COUNT, 1));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__OFFLINE_ALLOWED));
            dbc.bindValue(selChange.observe(b), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Placeholder Ref.*:");
            Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = COLUMN_COUNT - 1;
            t.setLayoutData(gd);
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__PLACEHOLDERREF));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Placeholder ID*:");
            Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = COLUMN_COUNT - 1;
            t.setLayoutData(gd);
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__PLACEHOLDERID));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "HTML Template:");
            Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__TEMPLATE, TEMPLATE__FILE));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
            Button b = toolkit.createButton(sectionClient, "Workspace ...", SWT.NONE);
            b.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(final SelectionEvent e) {
                    FilteredResourcesSelectionDialog d = new FilteredResourcesSelectionDialog(
                            getSite().getShell(), false,
                            ((IFileEditorInput) getEditorInput()).getFile().getProject(), IResource.FILE) {
                        @Override
                        protected IStatus validateItem(final Object item) {
                            IFile f = (IFile) item;
                            if (f.getParent() instanceof IProject) {
                                return new Status(IStatus.ERROR, JavaFXUIPlugin.PLUGIN_ID,
                                        "The selected resource has to be part of the source folder");
                            }
                            if (!f.getName().endsWith(JavaFXUIPlugin.FILEEXTENSION_HTML_TEMPLATE)) {
                                return new Status(IStatus.ERROR, JavaFXUIPlugin.PLUGIN_ID,
                                        "The selected resource does not seem to be a html file");
                            }
                            return super.validateItem(item);
                        }
                    };

                    if (d.open() == ResourceSelectionDialog.OK) {
                        Object[] rv = d.getResult();
                        if (rv.length == 1) {
                            IFile f = (IFile) rv[0];
                            IJavaElement j = JavaCore.create(f.getParent());
                            String template = null;
                            if (j instanceof IPackageFragment) {
                                IPackageFragment p = (IPackageFragment) j;
                                template = p.getElementName().replace('.', '/') + "/" + f.getName();
                            } else if (j instanceof IPackageFragmentRoot) {
                                IPackageFragmentRoot p = (IPackageFragmentRoot) j;
                                template = f.getName();
                            } else {
                                MessageDialog.openInformation(getSite().getShell(), "Not valid",
                                        "The selected resource has to be part of the source folder");
                            }
                            if (template != null) {
                                if (getTask().getDeploy().getTemplate() == null) {
                                    Command cmd = new SetCommand(editingDomain, getTask().getDeploy(),
                                            DEPLOY__TEMPLATE, ParametersFactory.eINSTANCE.createTemplate());
                                    if (cmd.canExecute()) {
                                        cmd.execute();
                                    }
                                }
                                Command cmd = new SetCommand(editingDomain, getTask().getDeploy().getTemplate(),
                                        TEMPLATE__FILE, template);
                                if (cmd.canExecute()) {
                                    cmd.execute();
                                }
                            }
                        }
                    }
                }
            });
        }

        {
            toolkit.createLabel(sectionClient, "Template Output File:");
            Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = COLUMN_COUNT - 1;
            t.setLayoutData(gd);
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__TEMPLATE, TEMPLATE__TO_FILE));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Webstart Splash:")
                    .setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
            Composite container = toolkit.createComposite(sectionClient);
            GridLayout gl = new GridLayout(2, false);
            gl.marginBottom = gl.marginHeight = gl.marginLeft = gl.marginRight = gl.marginTop = gl.marginWidth = 0;
            container.setLayout(gl);
            GridData gdContainer = new GridData(GridData.FILL_HORIZONTAL);
            gdContainer.horizontalSpan = COLUMN_COUNT - 1;
            container.setLayoutData(gdContainer);

            Composite tableContainer = toolkit.createComposite(container);
            Table t = toolkit.createTable(tableContainer,
                    SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            t.setHeaderVisible(true);
            t.setLinesVisible(true);

            GridData gdTable = new GridData(GridData.FILL_HORIZONTAL);
            gdTable.heightHint = t.getItemHeight() * 5;
            tableContainer.setLayoutData(gdTable);

            TableColumnLayout tablelayout = new TableColumnLayout();

            final TableViewer v = new TableViewer(t);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.heightHint = t.getItemHeight() * 5;
            v.getControl().setLayoutData(gd);
            v.setContentProvider(ArrayContentProvider.getInstance());

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(final Object element) {
                        return ((Splash) element).getMode().getName();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(10, 100, false));
                c.getColumn().setText("Mode");
            }

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(final Object element) {
                        return ((Splash) element).getHref();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(90));
                c.getColumn().setText("URL");
            }
            tableContainer.setLayout(tablelayout);
            v.setInput(task.getDeploy().getInfo().getSplash());

            Composite buttonComp = toolkit.createComposite(container);
            buttonComp.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false));
            buttonComp.setLayout(new GridLayout());

            {
                Button b = toolkit.createButton(buttonComp, "Add ...", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        if (handleAddSplash()) {
                            v.setInput(task.getDeploy().getInfo().getSplash());
                            v.setSelection(new StructuredSelection(task.getDeploy().getInfo().getSplash()
                                    .get(task.getDeploy().getInfo().getSplash().size() - 1)));
                        }
                    }
                });
            }

            {
                Button b = toolkit.createButton(buttonComp, "Remove", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        Splash value = (Splash) ((IStructuredSelection) v.getSelection()).getFirstElement();
                        if (value != null) {
                            if (handleRemoveSplash(value)) {
                                v.setInput(getTask().getDeploy().getInfo().getSplash());
                            }
                        } else {
                            MessageDialog.openWarning(getSite().getShell(), "Warning",
                                    "Please select an entry");
                        }
                    }
                });
            }
        }

        {
            toolkit.createLabel(sectionClient, "Webstart Icons:")
                    .setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
            Composite container = toolkit.createComposite(sectionClient);
            GridLayout gl = new GridLayout(2, false);
            gl.marginBottom = gl.marginHeight = gl.marginLeft = gl.marginRight = gl.marginTop = gl.marginWidth = 0;
            container.setLayout(gl);
            GridData gdContainer = new GridData(GridData.FILL_HORIZONTAL);
            gdContainer.horizontalSpan = COLUMN_COUNT - 1;
            container.setLayoutData(gdContainer);

            Composite tableContainer = toolkit.createComposite(container);
            Table t = toolkit.createTable(tableContainer,
                    SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            t.setHeaderVisible(true);
            t.setLinesVisible(true);

            GridData gdTable = new GridData(GridData.FILL_HORIZONTAL);
            gdTable.heightHint = t.getItemHeight() * 5;
            tableContainer.setLayoutData(gdTable);

            TableColumnLayout tablelayout = new TableColumnLayout();

            final TableViewer v = new TableViewer(t);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.heightHint = t.getItemHeight() * 5;
            v.getControl().setLayoutData(gd);
            v.setContentProvider(ArrayContentProvider.getInstance());

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return ((Icon) element).getDepth();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(10, 50, false));
                c.getColumn().setText("Depth");
            }

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return ((Icon) element).getKind().getName();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(10, 100, false));
                c.getColumn().setText("Kind");
            }

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return ((Icon) element).getWidth();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(10, 50, false));
                c.getColumn().setText("Width");
            }

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return ((Icon) element).getHeight();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(10, 50, false));
                c.getColumn().setText("Height");
            }

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return ((Icon) element).getHref();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(60));
                c.getColumn().setText("Url");
            }
            tableContainer.setLayout(tablelayout);
            v.setInput(task.getDeploy().getInfo().getIcon());

            Composite buttonComp = toolkit.createComposite(container);
            buttonComp.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false));
            buttonComp.setLayout(new GridLayout());

            {
                Button b = toolkit.createButton(buttonComp, "Add ...", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        if (handleAddIcon()) {
                            v.setInput(task.getDeploy().getInfo().getIcon());
                            v.setSelection(new StructuredSelection(task.getDeploy().getInfo().getIcon()
                                    .get(task.getDeploy().getInfo().getIcon().size() - 1)));
                        }
                    }
                });
            }

            {
                Button b = toolkit.createButton(buttonComp, "Remove", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        Icon value = (Icon) ((IStructuredSelection) v.getSelection()).getFirstElement();
                        if (value != null) {
                            if (handleRemoveIcon(value)) {
                                v.setInput(task.getDeploy().getInfo().getIcon());
                            }
                        } else {
                            MessageDialog.openWarning(getSite().getShell(), "Warning",
                                    "Please select an entry");
                        }
                    }
                });
            }
        }

        {
            toolkit.createLabel(sectionClient, "Additional META-INF files:")
                    .setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
            Composite container = toolkit.createComposite(sectionClient);
            GridLayout gl = new GridLayout(2, false);
            gl.marginBottom = gl.marginHeight = gl.marginLeft = gl.marginRight = gl.marginTop = gl.marginWidth = 0;
            container.setLayout(gl);
            GridData gdContainer = new GridData(GridData.FILL_HORIZONTAL);
            gdContainer.horizontalSpan = COLUMN_COUNT - 1;
            container.setLayoutData(gdContainer);

            Composite tableContainer = toolkit.createComposite(container);
            Table t = toolkit.createTable(tableContainer,
                    SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            t.setHeaderVisible(true);
            t.setLinesVisible(true);

            GridData gdTable = new GridData(GridData.FILL_HORIZONTAL);
            gdTable.heightHint = t.getItemHeight() * 5;
            tableContainer.setLayoutData(gdTable);

            TableColumnLayout tablelayout = new TableColumnLayout();

            final TableViewer v = new TableViewer(t);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.heightHint = t.getItemHeight() * 5;
            v.getControl().setLayoutData(gd);
            v.setContentProvider(ArrayContentProvider.getInstance());

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return ((KeyValuePair) element).getKey();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(33));
                c.getColumn().setText("Folder");
            }

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return ((KeyValuePair) element).getValue();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(67));
                c.getColumn().setText("File");
            }
            tableContainer.setLayout(tablelayout);
            v.setInput(task.getFiles());

            Composite buttonComp = toolkit.createComposite(container);
            buttonComp.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false));
            buttonComp.setLayout(new GridLayout());

            {
                Button b = toolkit.createButton(buttonComp, "Add ...", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        if (handleAddMetaInfFile()) {
                            v.setInput(task.getFiles());
                            v.setSelection(
                                    new StructuredSelection(task.getFiles().get(task.getFiles().size() - 1)));
                        }
                    }
                });
            }

            {
                Button b = toolkit.createButton(buttonComp, "Remove", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        KeyValuePair value = (KeyValuePair) ((IStructuredSelection) v.getSelection())
                                .getFirstElement();
                        if (value != null) {
                            if (handleRemoveMetaInfFile(value)) {
                                v.setInput(task.getFiles());
                            }
                        } else {
                            MessageDialog.openWarning(getSite().getShell(), "Warning",
                                    "Please select an entry");
                        }
                    }
                });
            }
        }

        {
            toolkit.createLabel(sectionClient, "Fonts:")
                    .setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
            Composite container = toolkit.createComposite(sectionClient);
            GridLayout gl = new GridLayout(2, false);
            gl.marginBottom = gl.marginHeight = gl.marginLeft = gl.marginRight = gl.marginTop = gl.marginWidth = 0;
            container.setLayout(gl);
            GridData gdContainer = new GridData(GridData.FILL_HORIZONTAL);
            gdContainer.horizontalSpan = COLUMN_COUNT - 1;
            container.setLayoutData(gdContainer);

            Composite tableContainer = toolkit.createComposite(container);
            Table t = toolkit.createTable(tableContainer,
                    SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            t.setHeaderVisible(true);
            t.setLinesVisible(true);

            GridData gdTable = new GridData(GridData.FILL_HORIZONTAL);
            gdTable.heightHint = t.getItemHeight() * 5;
            tableContainer.setLayoutData(gdTable);

            TableColumnLayout tablelayout = new TableColumnLayout();

            final TableViewer v = new TableViewer(t);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.heightHint = t.getItemHeight() * 5;
            v.getControl().setLayoutData(gd);
            final ArrayContentProvider cp = new ArrayContentProvider();
            v.setContentProvider(cp);

            {
                IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                        ParametersPackage.Literals.KEY_VALUE_PAIR__KEY);
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                TableColumn tc = c.getColumn();
                tc.setText("Font name");
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return ((KeyValuePair) element).getKey();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(33));
            }

            {
                IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                        ParametersPackage.Literals.KEY_VALUE_PAIR__VALUE);
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                TableColumn tc = c.getColumn();
                tc.setText("File");
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return ((KeyValuePair) element).getValue();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(67));
            }
            tableContainer.setLayout(tablelayout);
            v.setInput(task.getFonts());

            Composite buttonComp = toolkit.createComposite(container);
            buttonComp.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false));
            buttonComp.setLayout(new GridLayout());

            {
                Button b = toolkit.createButton(buttonComp, "Add ...", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        if (handleAddFont()) {
                            final KeyValuePair newFont = task.getFonts().get(task.getFonts().size() - 1);
                            v.refresh();
                            v.setSelection(new StructuredSelection(newFont));
                        }
                    }
                });
            }

            {
                Button b = toolkit.createButton(buttonComp, "Remove", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        KeyValuePair value = (KeyValuePair) ((IStructuredSelection) v.getSelection())
                                .getFirstElement();
                        if (value != null) {
                            if (handleRemoveFont(value)) {
                                v.setInput(task.getFonts());
                            }
                        } else {
                            MessageDialog.openWarning(getSite().getShell(), "Warning",
                                    "Please select an entry");
                        }
                    }
                });
            }
        }
        section.setClient(sectionClient);
    }
    int index = addPage(composite);
    setPageText(index, "Deploy");
}

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.JFXBuildConfigurationEditor.java

License:Open Source License

private String handleSplashImage(Shell shell) {
    FilteredResourcesSelectionDialog d = new FilteredResourcesSelectionDialog(shell, false,
            ((IFileEditorInput) getEditorInput()).getFile().getProject(), IResource.FILE) {
        @Override/*from w w  w .j  a va 2  s .  c  o  m*/
        protected IStatus validateItem(Object item) {
            IFile f = (IFile) item;
            if (f.getParent() instanceof IProject) {
                return new Status(IStatus.ERROR, JavaFXUIPlugin.PLUGIN_ID,
                        "The selected resource has to part of the source folder");
            }
            return super.validateItem(item);
        }
    };
    if (d.open() == ResourceSelectionDialog.OK) {
        Object[] rv = d.getResult();
        if (rv.length == 1) {
            IFile f = (IFile) rv[0];
            IJavaElement j = JavaCore.create(f.getParent());
            if (j instanceof IPackageFragment) {
                IPackageFragment p = (IPackageFragment) j;
                return p.getElementName().replace('.', '/') + "/" + f.getName();
            } else if (j instanceof IPackageFragmentRoot) {
                return f.getName();
            } else {
                MessageDialog.openInformation(shell, "Not valid",
                        "The selected resource has to part of the source folder");
            }
        }
    }
    return null;
}

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.refactoring.RefactoringUtil.java

License:Open Source License

/**
 * @param resource/*from   w ww.j  av a2s .  co  m*/
 *            resource
 * @param name
 *            name
 * @return element name
 */
private static String getNonJavaElementName(final IResource resource, final String name) {
    IJavaElement j = JavaCore.create(resource.getParent());
    if (j instanceof IPackageFragment) {
        IPackageFragment p = (IPackageFragment) j;
        return p.getElementName().replace('.', '/') + "/" + name;
    } else if (j instanceof IPackageFragmentRoot) {
        return resource.getName();
    } else {
        return "";
    }
}

From source file:at.bestsolution.efxclipse.tooling.pde.e4.project.E4NewProjectWizard.java

License:Open Source License

/**
 * create products extension detail/*from  w  w  w  .j  a v  a2  s . c  om*/
 * 
 * @param project
 */
public void createApplicationResources(IProject project, IProgressMonitor monitor) {
    Map<String, String> map = fApplicationPage.getData();
    if (map == null || map.get(NewApplicationWizardPage.PRODUCT_NAME) == null)
        return;

    // If the project has invalid characters, the plug-in name would replace
    // them with underscores, product name does the same
    String pluginName = map.get(NewApplicationWizardPage.PRODUCT_NAME);
    String xmiPath = map.get(NewApplicationWizardPage.APPLICATION_XMI_PROPERTY);

    // If there's no Activator created we create default package
    if (!fPluginData.doGenerateClass()) {
        String packageName = fPluginData.getId();
        IPath path = new Path(packageName.replace('.', '/'));
        if (fPluginData.getSourceFolderName().trim().length() > 0)
            path = new Path(fPluginData.getSourceFolderName()).append(path);

        try {
            CoreUtility.createFolder(project.getFolder(path));
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    IJavaProject javaProject = JavaCore.create(project);
    IPackageFragment fragment = null;

    try {
        for (IPackageFragment element : javaProject.getPackageFragments()) {
            if (element.getKind() == IPackageFragmentRoot.K_SOURCE) {
                fragment = element;
            }
        }
    } catch (JavaModelException e1) {
        e1.printStackTrace();
    }

    if (xmiPath != null && xmiPath.trim().length() > 0) {
        // Create a resource set
        //
        ResourceSet resourceSet = new ResourceSetImpl();

        // Get the URI of the model file.
        //
        URI fileURI = URI.createPlatformResourceURI(project.getName() + "/" + xmiPath, true);

        // Create a resource for this file.
        //
        Resource resource = resourceSet.createResource(fileURI);

        MApplication application = MApplicationFactory.INSTANCE.createApplication();

        application.setElementId("org.eclipse.e4.ide.application");

        MAddon addon = MApplicationFactory.INSTANCE.createAddon();
        addon.setElementId("org.eclipse.e4.core.commands.service");
        addon.setContributionURI(
                "bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon");
        application.getAddons().add(addon);

        addon = MApplicationFactory.INSTANCE.createAddon();
        addon.setElementId("org.eclipse.e4.ui.contexts.service");
        addon.setContributionURI(
                "bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon");
        application.getAddons().add(addon);

        addon = MApplicationFactory.INSTANCE.createAddon();
        addon.setElementId("at.bestsolution.efxclipse.runtime.bindings.e4.service");
        addon.setContributionURI(
                "bundleclass://at.bestsolution.efxclipse.runtime.bindings.e4/at.bestsolution.efxclipse.runtime.bindings.e4.BindingServiceAddon");
        application.getAddons().add(addon);

        addon = MApplicationFactory.INSTANCE.createAddon();
        addon.setElementId("org.eclipse.e4.ui.workbench.commands.model");
        addon.setContributionURI(
                "bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon");
        application.getAddons().add(addon);

        addon = MApplicationFactory.INSTANCE.createAddon();
        addon.setElementId("org.eclipse.e4.ui.workbench.contexts.model");
        addon.setContributionURI(
                "bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon");
        application.getAddons().add(addon);

        addon = MApplicationFactory.INSTANCE.createAddon();
        addon.setElementId("at.bestsolution.efxclipse.runtime.bindings.e4.model");
        addon.setContributionURI(
                "bundleclass://at.bestsolution.efxclipse.runtime.bindings.e4/at.bestsolution.efxclipse.runtime.bindings.e4.BindingProcessingAddon");
        application.getAddons().add(addon);

        MBindingContext rootContext = MCommandsFactory.INSTANCE.createBindingContext();
        rootContext.setElementId("org.eclipse.ui.contexts.dialogAndWindow");
        rootContext.setName("In Dialog and Windows");

        MBindingContext childContext = MCommandsFactory.INSTANCE.createBindingContext();
        childContext.setElementId("org.eclipse.ui.contexts.window");
        childContext.setName("In Windows");
        rootContext.getChildren().add(childContext);

        childContext = MCommandsFactory.INSTANCE.createBindingContext();
        childContext.setElementId("org.eclipse.ui.contexts.dialog");
        childContext.setName("In Dialogs");
        rootContext.getChildren().add(childContext);

        application.getRootContext().add(rootContext);
        application.getBindingContexts().add(rootContext);

        resource.getContents().add((EObject) application);

        MCommand openCommand = createCommand("media.open", "openMedia", "OpenHandler", "M1+O", pluginName,
                fragment, application);
        MCommand refreshCommand = createCommand("media.refresh", "refreshMedia", "RefreshHandler", "M1+R",
                pluginName, fragment, application);

        MTrimmedWindow mainWindow = MBasicFactory.INSTANCE.createTrimmedWindow();
        mainWindow.setElementId("org.efxclipse.e4.mainWindow");
        mainWindow.getPersistedState().put("fx.stage.decoration", "platform:/plugin/" + pluginName + "/"
                + fragment.getElementName().replace('.', '/') + "/decoration/TopArea.fxml");
        application.getChildren().add(mainWindow);
        {
            mainWindow.setLabel(pluginName);
            mainWindow.setX(30);
            mainWindow.setY(30);
            mainWindow.setWidth(1024);
            mainWindow.setHeight(768);

            // Top-Sash
            {
                MPartSashContainer sash = MBasicFactory.INSTANCE.createPartSashContainer();
                sash.setHorizontal(true);

                // Create a left part
                {
                    MPart part = MBasicFactory.INSTANCE.createPart();
                    part.setContributionURI("bundleclass://" + pluginName + "/" + fragment.getElementName()
                            + ".parts.MediaListPart");
                    part.setContainerData("0.3");
                    sash.getChildren().add(part);
                }

                // Create a right a stack
                {
                    MPartStack stack = MBasicFactory.INSTANCE.createPartStack();
                    stack.setContainerData("0.7");
                    stack.setElementId("content.stack");
                    sash.getChildren().add(stack);
                }

                mainWindow.getChildren().add(sash);
            }

            // WindowTrim
            {
                MTrimBar trimBar = MBasicFactory.INSTANCE.createTrimBar();
                mainWindow.getTrimBars().add(trimBar);

                MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar();
                toolBar.setElementId("org.efxclipse.e4.maintoolbar");
                trimBar.getChildren().add(toolBar);

                MHandledToolItem toolItemOpen = MMenuFactory.INSTANCE.createHandledToolItem();
                toolBar.getChildren().add(toolItemOpen);
                toolItemOpen.setElementId("org.efxclipse.e4.toolitem.open");
                toolItemOpen.setIconURI("platform:/plugin/" + pluginName + "/icons/edit-image-face-show.png");
                toolItemOpen.setCommand(openCommand);

                MHandledToolItem toolItemSave = MMenuFactory.INSTANCE.createHandledToolItem();
                toolBar.getChildren().add(toolItemSave);
                toolItemSave.setElementId("org.efxclipse.e4.toolitem.save");
                toolItemSave.setIconURI("platform:/plugin/" + pluginName + "/icons/system-reboot.png");
                toolItemSave.setCommand(refreshCommand);
            }
        }

        Map<Object, Object> options = new HashMap<Object, Object>();
        options.put(XMLResource.OPTION_ENCODING, "UTF-8");
        try {
            resource.save(options);
        } catch (IOException e) {
            PDEPlugin.logException(e);
        }
    }

    IFile f = project.getFile(new Path(project.getName() + ".product.launch"));
    E4LaunchDef def = new E4LaunchDef();
    def.setProjectName(project.getName());
    def.getTargetPlugins().addAll(E4LaunchDef.getE4TargetPlugins());
    def.getWorkbenchPlugins().add(new PluginLaunchDef(project.getName()));
    try {
        ByteArrayInputStream in = new ByteArrayInputStream(
                new LaunchGenerator().generate(def).toString().getBytes());
        f.create(in, true, monitor);
        in.close();
    } catch (CoreException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String cssPath = map.get(NewApplicationWizardPage.APPLICATION_CSS_PROPERTY);
    if (cssPath != null && cssPath.trim().length() > 0) {
        IFile file = project.getFile(cssPath);

        try {
            prepareFolder(file.getParent(), monitor);

            URL corePath = ResourceLocator.getProjectTemplateFiles("css/default.css");
            file.create(corePath.openStream(), true, monitor);
        } catch (Exception e) {
            PDEPlugin.logException(e);
        }
    }

    String template_id = "common";
    Set<String> binaryExtentions = new HashSet<String>();
    binaryExtentions.add(".gif");
    binaryExtentions.add(".png");
    binaryExtentions.add(".jpg");
    binaryExtentions.add(".flv");

    Map<String, String> keys = new HashMap<String, String>();
    keys.put("projectName", pluginName);
    keys.put("packageName", fragment.getElementName() + ".handlers");
    keys.put("packageName_parts", fragment.getElementName() + ".parts");
    keys.put("packageName_model", fragment.getElementName() + ".model");
    keys.put("packageName_decoration", fragment.getElementName() + ".decoration");

    try {
        URL corePath = ResourceLocator.getProjectTemplateFiles(template_id);
        IRunnableWithProgress op = new TemplateOperation(corePath, project, keys, binaryExtentions);
        getContainer().run(false, true, op);
    } catch (Exception e) {
        PDEPlugin.logException(e);
    }

    try {
        URL corePath = ResourceLocator.getProjectTemplateFiles("src");
        IRunnableWithProgress op = new TemplateOperation(corePath, (IContainer) fragment.getResource(), keys,
                binaryExtentions);
        getContainer().run(false, true, op);
    } catch (Exception e) {
        PDEPlugin.logException(e);
    }
}

From source file:at.bestsolution.efxclipse.tooling.pde.e4.project.E4NewProjectWizard.java

License:Open Source License

private MCommand createCommand(String commandId, String name, String className, String keyBinding,
        String projectName, IPackageFragment fragment, MApplication application) {
    MCommand command = MCommandsFactory.INSTANCE.createCommand();
    command.setCommandName(name);/*from w  ww  . j  av  a  2  s  . c  o m*/
    command.setElementId(commandId);
    application.getCommands().add(command);
    {
        // Create Quit handler for command
        MHandler quitHandler = MCommandsFactory.INSTANCE.createHandler();
        quitHandler.setCommand(command);
        quitHandler.setContributionURI(
                "bundleclass://" + projectName + "/" + fragment.getElementName() + ".handlers." + className);
        application.getHandlers().add(quitHandler);

        MKeyBinding binding = MCommandsFactory.INSTANCE.createKeyBinding();
        binding.setKeySequence(keyBinding);
        binding.setCommand(command);
        List<MBindingTable> tables = application.getBindingTables();
        if (tables.size() == 0) {
            MBindingContext rootContext = null;
            if (application.getRootContext().size() > 0) {
                rootContext = application.getRootContext().get(0);
            } else {
                rootContext = MCommandsFactory.INSTANCE.createBindingContext();
                rootContext.setElementId("org.eclipse.ui.contexts.dialogAndWindow");
                rootContext.setName("In Dialog and Windows");
                application.getRootContext().add(rootContext);
            }
            MBindingTable table = MCommandsFactory.INSTANCE.createBindingTable();
            table.setBindingContext(rootContext);
            tables.add(table);
        }
        tables.get(0).getBindings().add(binding);
    }
    return command;
}