Example usage for org.eclipse.jface.window ApplicationWindow ApplicationWindow

List of usage examples for org.eclipse.jface.window ApplicationWindow ApplicationWindow

Introduction

In this page you can find the example usage for org.eclipse.jface.window ApplicationWindow ApplicationWindow.

Prototype

public ApplicationWindow(Shell parentShell) 

Source Link

Document

Create an application window instance, whose shell will be created under the given parent shell.

Usage

From source file:com.hudson.hibernatesynchronizer.properties.HibernateProperties.java

License:Apache License

private void addGeneral(Composite parent) {

    Composite subComp = new Composite(parent, SWT.NULL);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;//ww  w. jav  a2 s  .c om
    subComp.setLayoutData(gd);
    generationEnabled = new BooleanFieldEditor(Constants.PROP_GENERATION_ENABLED,
            "I would like to have the synchronization performed automatically.", subComp);
    generationEnabled.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            checkScreen();
        }
    });
    generationEnabled.setPreferenceStore(getLocalPreferenceStore());
    generationEnabled.load();

    Label label = new Label(subComp, SWT.NULL);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    IJavaProject javaProject = (JavaProject) JavaCore.create((IProject) getElement());
    List sourceRoots = new ArrayList();
    try {
        String value = Plugin.getProperty(getElement(), Constants.PROP_SOURCE_LOCATION);
        IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots();
        for (int i = 0; i < roots.length; i++) {
            try {
                if (null != roots[i].getCorrespondingResource() && roots[i].getJavaProject().equals(javaProject)
                        && !roots[i].isArchive()) {
                    sourceRoots.add(roots[i].getPath().toOSString());
                }
            } catch (JavaModelException jme) {
            }
        }
        if (sourceRoots.size() > 1) {
            Label pathLabel = new Label(parent, SWT.NONE);
            pathLabel.setText("Source Location");
            sourceLocation = new Combo(parent, SWT.READ_ONLY);
            int selection = 0;
            for (int i = 0; i < sourceRoots.size(); i++) {
                sourceLocation.add(sourceRoots.get(i).toString());
                if (null != value && value.equals(sourceRoots.get(i).toString())) {
                    selection = i;
                }
            }
            sourceLocation.select(selection);
        }
    } catch (Exception e) {
    }

    TabFolder folder = new TabFolder(parent, SWT.NONE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    gd.grabExcessHorizontalSpace = true;
    folder.setLayoutData(gd);
    TabItem item = new TabItem(folder, SWT.NONE);
    item.setText("Value Objects");
    Composite composite = new Composite(folder, SWT.NULL);
    GridLayout gl = new GridLayout(1, false);
    composite.setLayout(gl);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    composite.setLayoutData(gd);
    item.setControl(composite);

    Composite tComp = new Composite(composite, SWT.NONE);
    boEnabled = new BooleanFieldEditor(Constants.PROP_GENERATION_VALUE_OBJECT_ENABLED,
            "I would like to have value objects created for me.", tComp);
    boEnabled.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            checkScreen();
        }
    });
    boEnabled.setPreferenceStore(getLocalPreferenceStore());
    boEnabled.load();

    // Path text field
    baseGroup = new Group(composite, SWT.NULL);
    baseGroup.setText("Base Package Location");
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    baseGroup.setLayout(gridLayout);
    baseGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

    String[][] params = new String[3][2];
    params[0][0] = Constants.PROP_VALUE_RELATIVE;
    params[0][1] = Constants.PROP_VALUE_RELATIVE;
    params[1][0] = Constants.PROP_VALUE_ABSOLUTE;
    params[1][1] = Constants.PROP_VALUE_ABSOLUTE;
    params[2][0] = "Same Package";
    params[2][1] = Constants.PROP_VALUE_SAME;
    basePackageStyle = new RadioGroupFieldEditor(Constants.PROP_BASE_VO_PACKAGE_STYLE, "", 3, params,
            baseGroup);
    basePackageStyle.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            basePackageStyleSelection = event.getNewValue().toString();
            checkScreen();
        }
    });
    basePackageStyle.setPreferenceStore(getLocalPreferenceStore());
    basePackageStyle.load();

    Composite bgc1 = new Composite(baseGroup, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    bgc1.setLayout(gridLayout);
    bgc1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

    basePackageHelp = new Label(bgc1, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 3;
    basePackageHelp.setLayoutData(gd);

    basePackageNameLbl = new Label(bgc1, SWT.NULL);
    basePackageNameLbl.setText("Package:");
    basePackageText = new Text(bgc1, SWT.SINGLE | SWT.BORDER);
    basePackageText.setSize(50, 12);
    gd = new GridData(
            GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
    gd.widthHint = 230;
    basePackageText.setLayoutData(gd);
    String basePackageString = Plugin.getProperty(getElement(), Constants.PROP_BASE_VO_PACKAGE_NAME);
    if (null != basePackageString)
        basePackageText.setText(basePackageString);
    else
        basePackageText.setText(Constants.DEFAULT_BASE_VO_PACKAGE);

    basePackageSelectionButton = new Button(bgc1, SWT.NATIVE);
    basePackageSelectionButton.setText("Browse");
    basePackageSelectionButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            try {
                JavaProject javaProject = (JavaProject) JavaCore.create((IProject) getElement());
                IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
                SelectionDialog sd = JavaUI.createPackageDialog(getShell(), javaProject,
                        IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);
                sd.open();
                Object[] objects = sd.getResult();
                if (null != objects && objects.length > 0) {
                    PackageFragment pf = (PackageFragment) objects[0];
                    basePackageText.setText(pf.getElementName());
                }
            } catch (JavaModelException jme) {
                jme.printStackTrace();
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });

    item = new TabItem(folder, SWT.NONE);
    item.setText("Data Access Objects");
    composite = new Composite(folder, SWT.NULL);
    gl = new GridLayout(1, false);
    composite.setLayout(gl);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.grabExcessHorizontalSpace = true;
    composite.setLayoutData(gd);
    item.setControl(composite);

    tComp = new Composite(composite, SWT.NONE);
    managersEnabled = new BooleanFieldEditor(Constants.PROP_GENERATION_DAO_ENABLED,
            "I would like to have DAOs created for me.", tComp);
    managersEnabled.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            checkScreen();
        }
    });
    managersEnabled.setPreferenceStore(getLocalPreferenceStore());
    managersEnabled.load();

    new Label(parent, SWT.NULL);

    // Path text field
    managerGroup = new Group(composite, SWT.NULL);
    managerGroup.setText("Base Package Location");
    gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    managerGroup.setLayout(gridLayout);
    managerGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    params = new String[3][2];
    params[0][0] = Constants.PROP_VALUE_RELATIVE;
    params[0][1] = Constants.PROP_VALUE_RELATIVE;
    params[1][0] = Constants.PROP_VALUE_ABSOLUTE;
    params[1][1] = Constants.PROP_VALUE_ABSOLUTE;
    params[2][0] = "Same Package";
    params[2][1] = Constants.PROP_VALUE_SAME;
    managerPackageStyle = new RadioGroupFieldEditor(Constants.PROP_DAO_PACKAGE_STYLE, "", 3, params,
            managerGroup);
    managerPackageStyle.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            managerPackageStyleSelection = event.getNewValue().toString();
            checkScreen();
        }
    });
    managerPackageStyle.setPreferenceStore(getLocalPreferenceStore());
    managerPackageStyle.load();

    bgc1 = new Composite(managerGroup, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    bgc1.setLayout(gridLayout);
    bgc1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    managerPackageHelp = new Label(bgc1, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 3;
    managerPackageHelp.setLayoutData(gd);

    managerPackageNameLbl = new Label(bgc1, SWT.NULL);
    managerPackageNameLbl.setText("Package:");
    managerPackageText = new Text(bgc1, SWT.SINGLE | SWT.BORDER);
    managerPackageText.setSize(50, 12);
    gd = new GridData(
            GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    gd.widthHint = 230;
    managerPackageText.setLayoutData(gd);
    String managerPackageString = Plugin.getProperty(getElement(), Constants.PROP_DAO_PACKAGE_NAME);
    if (null != managerPackageString)
        managerPackageText.setText(managerPackageString);
    else
        managerPackageText.setText(Constants.DEFAULT_DAO_PACKAGE);

    managerPackageSelectionButton = new Button(bgc1, SWT.NATIVE);
    managerPackageSelectionButton.setText("Browse");
    managerPackageSelectionButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            try {
                JavaProject javaProject = (JavaProject) JavaCore.create((IProject) getElement());
                IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
                SelectionDialog sd = JavaUI.createPackageDialog(getShell(), javaProject,
                        IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);
                sd.open();
                Object[] objects = sd.getResult();
                if (null != objects && objects.length > 0) {
                    PackageFragment pf = (PackageFragment) objects[0];
                    managerPackageText.setText(pf.getElementName());
                }
            } catch (JavaModelException jme) {
                jme.printStackTrace();
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });

    subComp = new Composite(bgc1, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 3;
    subComp.setLayoutData(gd);
    managerUseBasePackage = new BooleanFieldEditor(Constants.PROP_BASE_DAO_USE_BASE_PACKAGE,
            "I would like the base DAOs in the base value object package", subComp);
    managerUseBasePackage.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            checkScreen();
        }
    });
    managerUseBasePackage.setPreferenceStore(getLocalPreferenceStore());
    managerUseBasePackage.load();

    baseManagerPackageStyleSelectionParent = new Composite(bgc1, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 3;
    baseManagerPackageStyleSelectionParent.setLayoutData(gd);
    params = new String[3][2];
    params[0][0] = Constants.PROP_VALUE_RELATIVE;
    params[0][1] = Constants.PROP_VALUE_RELATIVE;
    params[1][0] = Constants.PROP_VALUE_ABSOLUTE;
    params[1][1] = Constants.PROP_VALUE_ABSOLUTE;
    params[2][0] = "DAO Package";
    params[2][1] = Constants.PROP_VALUE_SAME;
    baseManagerPackageStyle = new RadioGroupFieldEditor(Constants.PROP_BASE_DAO_PACKAGE_STYLE,
            "Base DAO Location", 3, params, baseManagerPackageStyleSelectionParent);
    baseManagerPackageStyle.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            baseManagerPackageStyleSelection = event.getNewValue().toString();
            checkScreen();
        }
    });
    baseManagerPackageStyle.setPreferenceStore(getLocalPreferenceStore());
    baseManagerPackageStyle.load();

    baseManagerPackageNameLbl = new Label(bgc1, SWT.NULL);
    baseManagerPackageNameLbl.setText("Package:");
    baseManagerPackageText = new Text(bgc1, SWT.SINGLE | SWT.BORDER);
    baseManagerPackageText.setSize(50, 12);
    gd = new GridData(
            GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    gd.widthHint = 230;
    baseManagerPackageText.setLayoutData(gd);
    String baseManagerPackageString = Plugin.getProperty(getElement(), Constants.PROP_BASE_DAO_PACKAGE_NAME);
    if (null != baseManagerPackageString)
        baseManagerPackageText.setText(baseManagerPackageString);
    else
        baseManagerPackageText.setText(Constants.DEFAULT_BASE_DAO_PACKAGE);

    baseManagerPackageSelectionButton = new Button(bgc1, SWT.NATIVE);
    baseManagerPackageSelectionButton.setText("Browse");
    baseManagerPackageSelectionButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            try {
                JavaProject javaProject = (JavaProject) JavaCore.create((IProject) getElement());
                IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
                SelectionDialog sd = JavaUI.createPackageDialog(getShell(), javaProject,
                        IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);
                sd.open();
                Object[] objects = sd.getResult();
                if (null != objects && objects.length > 0) {
                    PackageFragment pf = (PackageFragment) objects[0];
                    baseManagerPackageText.setText(pf.getElementName());
                }
            } catch (JavaModelException jme) {
                jme.printStackTrace();
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });

    customManagerComposite = new Composite(composite, SWT.NONE);
    customManager = new BooleanFieldEditor(Constants.PROP_USE_CUSTOM_ROOT_DAO,
            "I would like to use a custom DAO root.", customManagerComposite);
    customManager.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            checkScreen();
        }
    });
    customManager.setPreferenceStore(getLocalPreferenceStore());
    customManager.load();

    managerRootComposite = new Composite(composite, SWT.NONE);
    managerRootComposite.setLayout(new GridLayout(3, false));
    ((GridLayout) managerRootComposite.getLayout()).horizontalSpacing = 9;
    gd = new GridData(GridData.FILL_HORIZONTAL);
    ;
    gd.grabExcessHorizontalSpace = true;
    managerRootComposite.setLayoutData(gd);
    Label lbl = new Label(managerRootComposite, SWT.NONE);
    lbl.setText("DAO Class:");
    daoRootClass = new Text(managerRootComposite, SWT.SINGLE | SWT.BORDER);
    String managerRootClassStr = Plugin.getProperty(getElement(), Constants.PROP_CUSTOM_ROOT_DAO_CLASS);
    if (null != managerRootClassStr)
        daoRootClass.setText(managerRootClassStr);

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.grabExcessHorizontalSpace = true;
    daoRootClass.setLayoutData(gd);
    Button managerRootButton = new Button(managerRootComposite, SWT.NATIVE);
    managerRootButton.setText("Browse");
    managerRootButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            try {
                JavaProject javaProject = (JavaProject) JavaCore.create((IProject) getElement());
                IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
                SelectionDialog sd = JavaUI.createTypeDialog(getShell(), new ApplicationWindow(getShell()),
                        searchScope, IJavaElementSearchConstants.CONSIDER_CLASSES, false);
                sd.open();
                Object[] objects = sd.getResult();
                if (null != objects && objects.length > 0) {
                    IType type = (IType) objects[0];
                    daoRootClass.setText(type.getFullyQualifiedName());
                }
            } catch (JavaModelException jme) {
                jme.printStackTrace();
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });

    lbl = new Label(managerRootComposite, SWT.NONE);
    lbl.setText("DAO Exception:");
    daoExceptionClass = new Text(managerRootComposite, SWT.SINGLE | SWT.BORDER);
    String daoExceptionClassStr = Plugin.getProperty(getElement(), Constants.PROP_BASE_DAO_EXCEPTION);
    if (null != daoExceptionClassStr)
        daoExceptionClass.setText(daoExceptionClassStr);
    else
        daoExceptionClass.setText("org.hibernate.HibernateException");

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.grabExcessHorizontalSpace = true;
    daoExceptionClass.setLayoutData(gd);
    Button daoExceptionButton = new Button(managerRootComposite, SWT.NATIVE);
    daoExceptionButton.setText("Browse");
    daoExceptionButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            try {
                JavaProject javaProject = (JavaProject) JavaCore.create((IProject) getElement());
                IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
                SelectionDialog sd = JavaUI.createTypeDialog(getShell(), new ApplicationWindow(getShell()),
                        searchScope, IJavaElementSearchConstants.CONSIDER_CLASSES, false);
                sd.open();
                Object[] objects = sd.getResult();
                if (null != objects && objects.length > 0) {
                    IType type = (IType) objects[0];
                    daoExceptionClass.setText(type.getFullyQualifiedName());
                }
            } catch (JavaModelException jme) {
                jme.printStackTrace();
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });
}

From source file:com.hudson.hibernatesynchronizer.properties.HibernateProperties.java

License:Apache License

private void addTemplates(Composite parent) {
    Composite tComp = new Composite(parent, SWT.NULL);
    GridLayout gl = new GridLayout(1, false);
    gl.horizontalSpacing = 0;//from w ww.  j  av  a  2 s  .  c  o  m
    gl.verticalSpacing = 0;
    tComp.setLayout(gl);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    tComp.setLayoutData(gd);

    Composite composite = new Composite(tComp, SWT.NULL);
    gl = new GridLayout(2, false);
    composite.setLayout(gl);
    gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    composite.setLayoutData(gd);

    templateTable = new Table(composite, SWT.BORDER | SWT.H_SCROLL | SWT.CHECK | SWT.FULL_SELECTION);
    templateTable.setVisible(true);
    templateTable.setLinesVisible(false);
    templateTable.setHeaderVisible(true);
    templateTable.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            int rowsChecked = 0;
            for (int i = 0; i < templateTable.getItemCount(); i++) {
                if (templateTable.getItem(i).getChecked())
                    rowsChecked++;
            }
            if (rowsChecked > 0) {
                exportButton.setEnabled(true);
                deleteButton.setEnabled(true);
            } else {
                exportButton.setEnabled(false);
                deleteButton.setEnabled(false);
            }
            if (templateTable.getSelectionIndex() >= 0) {
                editButton.setEnabled(true);
                deleteButton.setEnabled(true);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    templateTable.addKeyListener(new DeleteKeyListener(this, (IProject) getElement()));
    templateTable.addMouseListener(new TableDoubleClickListener(this));
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = 140;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    templateTable.setLayoutData(data);

    // create the columns
    TableColumn templateColumn = new TableColumn(templateTable, SWT.LEFT);
    TableColumn nameColumn = new TableColumn(templateTable, SWT.LEFT);
    TableColumn typeColumn = new TableColumn(templateTable, SWT.LEFT);
    templateColumn.setText("Template");
    nameColumn.setText("Name");
    ColumnLayoutData templateColumnLayout = new ColumnWeightData(50, false);
    ColumnLayoutData nameColumnLayout = new ColumnWeightData(50, false);

    // set columns in Table layout
    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(templateColumnLayout);
    tableLayout.addColumnData(nameColumnLayout);
    templateTable.setLayout(tableLayout);

    Composite buttonComposite = new Composite(composite, SWT.NULL);
    GridLayout fl = new GridLayout(1, false);
    fl.verticalSpacing = 2;
    buttonComposite.setLayout(fl);
    data = new GridData();
    data.horizontalAlignment = GridData.BEGINNING;
    data.verticalAlignment = GridData.BEGINNING;
    buttonComposite.setLayoutData(data);

    importButton = new Button(buttonComposite, SWT.NATIVE);
    importButton.setText("Import");
    importButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getShell());
            fd.setFilterExtensions(new String[] { "*.zip" });
            String fileName = fd.open();
            if (null != fileName) {
                try {
                    IProject project = (IProject) getElement();
                    long uniqueId = System.currentTimeMillis();
                    ZipFile zipFile = new ZipFile(new File(fileName), ZipFile.OPEN_READ);
                    for (Enumeration enumeration = zipFile.entries(); enumeration.hasMoreElements();) {
                        ZipEntry entry = (ZipEntry) enumeration.nextElement();
                        String currentEntry = entry.getName();
                        if (currentEntry.endsWith(".pt")) {
                            BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));
                            TemplateLocation templateLocation = new TemplateLocation(is, project);
                            if (null != templateLocation.getTemplate()) {
                                ResourceManager.getInstance(project).addTemplateLocation(templateLocation);
                            }
                        }
                    }
                    reloadTemplates();
                } catch (Exception exc) {
                    HSUtil.showError(exc.getMessage(), getShell());
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    exportButton = new Button(buttonComposite, SWT.NATIVE);
    exportButton.setText("Export");
    exportButton.setEnabled(false);
    exportButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getShell());
            fd.setFilterExtensions(new String[] { "*.zip" });
            String fileName = fd.open();
            if (null != fileName && fileName.trim().length() > 0) {
                fileName = fileName.trim();
                if (fileName.indexOf(".") < 0)
                    fileName = fileName + ".zip";
                try {
                    IProject project = (IProject) getElement();
                    long uniqueId = System.currentTimeMillis();
                    List projectTemplates = new ArrayList();
                    for (int i = 0; i < templateTable.getItemCount(); i++) {
                        if (templateTable.getItem(i).getChecked()) {
                            TemplateLocation templateLocation = (TemplateLocation) ResourceManager
                                    .getInstance(project).getTemplateLocations().get(i);
                            projectTemplates.add(templateLocation);
                            templateTable.getItem(i).setChecked(false);
                        }
                    }
                    exportButton.setEnabled(false);
                    ZipOutputStream zos = null;
                    try {
                        zos = new ZipOutputStream(new FileOutputStream(new File(fileName)));
                        for (Iterator i = projectTemplates.iterator(); i.hasNext();) {
                            TemplateLocation templateLocation = (TemplateLocation) i.next();
                            ZipEntry entry = new ZipEntry(uniqueId++ + ".pt");
                            zos.putNextEntry(entry);
                            zos.write(templateLocation.toString().getBytes());
                            zos.closeEntry();
                        }
                    } finally {
                        if (null != zos)
                            zos.close();
                    }
                    MessageDialog.openInformation(getShell(), "Export Complete", projectTemplates.size()
                            + " project templates sucessfully exported to " + fileName + ".");
                } catch (Exception exc) {
                    HSUtil.showError(exc.getMessage(), getShell());
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    new Label(buttonComposite, SWT.NULL);
    selectAllButton = new Button(buttonComposite, SWT.NATIVE);
    selectAllButton.setText("Select All");
    selectAllButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = templateTable.getItems();
            for (int i = 0; i < items.length; i++) {
                items[i].setChecked(true);
            }
            if (items.length > 0) {
                deleteButton.setEnabled(true);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    selectNoneButton = new Button(buttonComposite, SWT.NATIVE);
    selectNoneButton.setText("Deselect All");
    selectNoneButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = templateTable.getItems();
            for (int i = 0; i < items.length; i++) {
                items[i].setChecked(false);
            }
            if (templateTable.getSelection().length == 0) {
                deleteButton.setEnabled(false);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    buttonComposite = new Composite(tComp, SWT.NULL);
    fl = new GridLayout(3, false);
    fl.marginWidth = 5;
    fl.horizontalSpacing = 2;
    buttonComposite.setLayout(fl);
    data = new GridData();
    data.horizontalAlignment = GridData.BEGINNING;
    data.verticalAlignment = GridData.BEGINNING;
    data.horizontalSpan = 2;
    buttonComposite.setLayoutData(data);
    addButton = new Button(buttonComposite, SWT.NATIVE);
    addButton.setText("New");
    addButton.setVisible(true);
    addButton.addSelectionListener(new AddButtonListener(this, ((IProject) getElement())));
    editButton = new Button(buttonComposite, SWT.NATIVE);
    editButton.setText("Edit");
    editButton.addSelectionListener(new EditButtonListener(this));
    deleteButton = new Button(buttonComposite, SWT.NATIVE);
    deleteButton.setText("Delete");
    deleteButton.addSelectionListener(new DeleteButtonListener(this, ((IProject) getElement())));

    reloadTemplates();

    composite = new Composite(tComp, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    composite.setLayoutData(gd);

    Label label = new Label(composite, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    label.setText("Context Parameters");

    parametersTable = new Table(composite, SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION);
    parametersTable.setVisible(true);
    parametersTable.setLinesVisible(false);
    parametersTable.setHeaderVisible(true);
    parametersTable.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            editParameterButton.setEnabled(true);
            deleteParameterButton.setEnabled(true);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    parametersTable.addKeyListener(new ParameterDeleteKeyListener(this, (IProject) getElement()));
    parametersTable.addMouseListener(new ParameterDoubleClickListener(this));

    // create the columns
    TableColumn keyColumn = new TableColumn(parametersTable, SWT.LEFT);
    TableColumn valueColumn = new TableColumn(parametersTable, SWT.LEFT);
    keyColumn.setText("Name");
    valueColumn.setText("Value");
    ColumnLayoutData keyColumnLayout = new ColumnWeightData(35, false);
    ColumnLayoutData valueColumnLayout = new ColumnWeightData(65, false);

    // set columns in Table layout
    tableLayout = new TableLayout();
    tableLayout.addColumnData(keyColumnLayout);
    tableLayout.addColumnData(valueColumnLayout);
    parametersTable.setLayout(tableLayout);

    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = 50;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    parametersTable.setLayoutData(data);

    buttonComposite = new Composite(composite, SWT.NONE);
    data = new GridData();
    data.horizontalAlignment = GridData.BEGINNING;
    data.verticalAlignment = GridData.BEGINNING;
    buttonComposite.setLayoutData(data);
    fl = new GridLayout(3, false);
    fl.horizontalSpacing = 2;
    buttonComposite.setLayout(fl);
    buttonComposite.setVisible(true);
    addParameterButton = new Button(buttonComposite, SWT.NATIVE);
    addParameterButton.setText("New");
    addParameterButton.setVisible(true);
    addParameterButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
    addParameterButton.addSelectionListener(new AddParameterButtonListener(this, (IProject) getElement()));
    editParameterButton = new Button(buttonComposite, SWT.NATIVE);
    editParameterButton.setText("Edit");
    editParameterButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
    editParameterButton.addSelectionListener(new EditParameterButtonListener(this, (IProject) getElement()));
    deleteParameterButton = new Button(buttonComposite, SWT.NATIVE);
    deleteParameterButton.setText("Delete");
    deleteParameterButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
    deleteParameterButton
            .addSelectionListener(new DeleteParameterButtonListener(this, ((IProject) getElement())));

    reloadTemplateParameters();

    Composite subComp = new Composite(tComp, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.grabExcessHorizontalSpace = true;
    subComp.setLayoutData(gd);
    subComp.setLayout(new GridLayout(4, false));
    label = new Label(subComp, SWT.NONE);
    label.setText("Context Object");
    contextObject = new Text(subComp, SWT.BORDER);
    contextObject.setEnabled(false);
    contextObject.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 200;
    gd.grabExcessHorizontalSpace = true;
    contextObject.setLayoutData(gd);
    String contextObjString = Plugin.getProperty(getElement(), Constants.PROP_CONTEXT_OBJECT);
    if (null != contextObjString)
        contextObject.setText(contextObjString);

    Button contextObjectButton = new Button(subComp, SWT.NATIVE);
    contextObjectButton.setText("Browse");
    contextObjectButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            try {
                JavaProject javaProject = (JavaProject) JavaCore.create((IProject) getElement());
                IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
                SelectionDialog sd = JavaUI.createTypeDialog(getShell(), new ApplicationWindow(getShell()),
                        searchScope, IJavaElementSearchConstants.CONSIDER_CLASSES, false);
                sd.open();
                Object[] objects = sd.getResult();
                if (null != objects && objects.length > 0) {
                    IType type = (IType) objects[0];
                    contextObject.setText(type.getFullyQualifiedName());
                }
            } catch (JavaModelException jme) {
                jme.printStackTrace();
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });
    Button clearButton = new Button(subComp, SWT.NATIVE);
    clearButton.setText("Clear");
    clearButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            contextObject.setText("");
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });

    label = new Label(subComp, SWT.NONE);
    label.setText("Tip: You can reference this object in your templates as ${obj}");
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.grabExcessHorizontalSpace = true;
    label.setLayoutData(gd);
}

From source file:com.hudson.hibernatesynchronizer.wizard.NewMappingWizardPage.java

License:GNU General Public License

public Composite addProperties(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout(1, false);
    container.setLayout(layout);/* ww w  .  j ava2s  .  c  o  m*/
    layout.verticalSpacing = 9;

    Composite subComp = new Composite(container, SWT.NULL);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    gd.horizontalSpan = 2;
    subComp.setLayoutData(gd);
    layout = new GridLayout();
    subComp.setLayout(layout);
    layout.numColumns = 3;
    Label label = new Label(subComp, SWT.NULL);
    label.setText("Extension");
    extensionText = new Text(subComp, SWT.BORDER);
    String extension = Plugin.getDefault().getPreferenceStore().getString("Extension");
    if (null != extension && extension.trim().length() > 0)
        extensionText.setText(extension);
    else
        extensionText.setText("hbm");
    gd = new GridData();
    gd.widthHint = 150;
    gd.horizontalSpan = 2;
    extensionText.setLayoutData(gd);

    label = new Label(subComp, SWT.NULL);
    label.setText("Composite ID Name");
    compositeIdNameText = new Text(subComp, SWT.BORDER);
    String compositeIdName = Plugin.getDefault().getPreferenceStore().getString("CompositeIdName");
    if (null != compositeIdName && compositeIdName.trim().length() > 0)
        compositeIdNameText.setText(compositeIdName);
    else
        compositeIdNameText.setText("id");
    gd = new GridData();
    gd.widthHint = 150;
    gd.horizontalSpan = 2;
    compositeIdNameText.setLayoutData(gd);

    label = new Label(subComp, SWT.NULL);
    label.setText("ID Generator");
    generatorText = new Text(subComp, SWT.BORDER);
    String generator = Plugin.getDefault().getPreferenceStore().getString("Generator");
    if (null != generator && generator.trim().length() > 0)
        generatorText.setText(generator);
    else
        generatorText.setText("vm");
    gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    gd.widthHint = 150;
    generatorText.setLayoutData(gd);
    Button browseButton = new Button(subComp, SWT.NATIVE);
    browseButton.setText("Browse");
    browseButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            try {
                IJavaSearchScope searchScope = null;
                if (null != project) {
                    searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project });
                } else {
                    searchScope = SearchEngine.createWorkspaceScope();
                }
                SelectionDialog sd = JavaUI.createTypeDialog(getShell(), new ApplicationWindow(getShell()),
                        searchScope, IJavaElementSearchConstants.CONSIDER_CLASSES, false);
                sd.open();
                Object[] objects = sd.getResult();
                if (null != objects && objects.length > 0) {
                    IType type = (IType) objects[0];
                    generatorText.setText(type.getFullyQualifiedName());
                }
            } catch (JavaModelException jme) {
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }
    });

    new Label(subComp, SWT.NULL);

    setComp = new Composite(container, SWT.NULL);
    layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.grabExcessHorizontalSpace = true;
    subComp.setData(gd);
    createSets = new BooleanFieldEditor("CreateSets",
            "Generate Sets to represent inverse foreign relationships", setComp);
    Plugin.getDefault().getPreferenceStore().setDefault("CreateSets", true);
    createSets.setPreferenceStore(Plugin.getDefault().getPreferenceStore());
    createSets.load();
    createSets.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            useLazyLoading.setEnabled(createSets.getBooleanValue(), setComp);
        }
    });
    useLazyLoading = new BooleanFieldEditor("UseLazyLoading", "Use Lazy Loading", setComp);
    useLazyLoading.setPreferenceStore(Plugin.getDefault().getPreferenceStore());
    useLazyLoading.load();
    if (!createSets.getBooleanValue())
        useLazyLoading.setEnabled(false, setComp);
    startLowerCase = new BooleanFieldEditor("StartLowerCase", "Start Properties with Lower Case", setComp);
    startLowerCase.setPreferenceStore(Plugin.getDefault().getPreferenceStore());
    startLowerCase.load();
    startLowerCase.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            compositeIdNameCheck();
        }
    });

    subComp = new Composite(setComp, SWT.NULL);
    subComp.setLayout(new GridLayout(3, false));
    useProxies = new BooleanFieldEditor("UseProxies", "Use Proxy Classes", subComp);
    useProxies.setPreferenceStore(Plugin.getDefault().getPreferenceStore());
    useProxies.load();
    useProxies.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            setProxyComposite();
        }
    });
    proxyComposite = new Composite(subComp, SWT.NULL);
    proxyComposite.setLayout(new GridLayout(2, false));
    label = new Label(proxyComposite, SWT.NULL);
    label.setText("    Proxy Class Name");
    proxyNameText = new Text(proxyComposite, SWT.BORDER);
    String proxyClassName = Plugin.getDefault().getPreferenceStore().getString("ProxyClassName");
    if (null != proxyClassName && proxyClassName.trim().length() > 0)
        proxyNameText.setText(proxyClassName);
    else
        proxyNameText.setText("${className}Proxy");
    gd = new GridData();
    gd.widthHint = 150;
    proxyNameText.setLayoutData(gd);
    setProxyComposite();
    compositeIdNameCheck();
    return container;
}

From source file:org.emftext.tools.restricted.EvaluateOCLAction.java

License:Open Source License

private void process(final IFile file) {
    // open dialog with an input field where OCL expressions
    // can be inserted and another text field where the result is shown
    final Shell shell = new Shell(Display.getCurrent());

    final ApplicationWindow window = new ApplicationWindow(shell) {

        protected Control createContents(Composite parent) {
            parent.getShell().setSize(1024, 768);
            parent.getShell().setText("OCL Evaluator");

            Composite composite = new Composite(parent, SWT.NULL);

            GridLayout layout = new GridLayout();
            layout.makeColumnsEqualWidth = true;

            composite.setLayout(layout);

            final StyledText expressionTextField = new StyledText(composite, SWT.MULTI);
            expressionTextField.setEditable(false);
            setLayout(expressionTextField, true);
            expressionTextField.setWordWrap(true);

            final StyledText outputTextField = new StyledText(composite, SWT.MULTI);
            outputTextField.setEditable(false);
            outputTextField.setWordWrap(true);
            setLayout(outputTextField, true);

            final StyledText inputTextField = new StyledText(composite, SWT.MULTI);
            inputTextField.setEditable(true);
            setLayout(inputTextField, true);
            inputTextField.setText("Insert OCL expressions here...");
            inputTextField.setWordWrap(true);
            inputTextField.setFocus();//from  w  w  w. j a v  a  2  s. c  o m

            inputTextField.addModifyListener(new ModifyListener() {

                public void modifyText(ModifyEvent e) {
                    evaluateOCL(file, inputTextField.getText(), outputTextField, expressionTextField);
                }
            });

            inputTextField.addListener(SWT.Selection, new Listener() {

                public void handleEvent(Event event) {
                    int start = event.x;
                    int end = event.y;
                    String text = inputTextField.getText();
                    if (start != end) {
                        text = text.substring(start, end);
                    }
                    evaluateOCL(file, text, outputTextField, expressionTextField);
                }

            });

            final Button buttonInputDialog = new Button(composite, SWT.PUSH);
            buttonInputDialog.setText("Close");
            buttonInputDialog.addListener(SWT.Selection, new Listener() {
                public void handleEvent(Event event) {
                    close();
                }
            });
            return composite;
        }

        private void setLayout(final StyledText inputTextField, boolean fillVertically) {
            GridData layoutData = new GridData(GridData.VERTICAL_ALIGN_FILL);
            inputTextField.setLayoutData(layoutData);
            if (fillVertically) {
                layoutData.verticalAlignment = GridData.FILL;
                layoutData.grabExcessVerticalSpace = true;
            }
            layoutData.horizontalAlignment = GridData.FILL;
            layoutData.grabExcessHorizontalSpace = true;
        }
    };
    window.setStatus("OCL Evaluator");
    window.open();
}

From source file:org.jboss.ide.eclipse.freemarker.dialogs.ContextValueDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new GridLayout(3, false));

    Label label = new Label(composite, SWT.NULL);
    label.setText(Messages.ContextValueDialog_LABEL_NAME);
    keyText = new Text(composite, SWT.BORDER);
    if (null != contextValue) {
        keyText.setText(contextValue.name);
        keyText.setEnabled(false);/*from w w  w.jav  a 2 s. co  m*/
    }
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    gd.widthHint = 200;
    keyText.setLayoutData(gd);

    label = new Label(composite, SWT.NULL);
    label.setText(Messages.ContextValueDialog_LABEL_TYPE);
    valueText = new Text(composite, SWT.BORDER);
    valueText.setEnabled(false);
    valueText.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 250;
    valueText.setLayoutData(gd);
    if (null != contextValue && null != contextValue.objClass)
        valueText.setText(contextValue.objClass.getName());
    Button browse = new Button(composite, 8);
    browse.setText(Messages.ContextValueDialog_BUTTON_BROWSE);
    browse.addMouseListener(new MouseListener() {
        @Override
        public void mouseDown(MouseEvent e) {
            try {
                IJavaProject javaProject = JavaCore.create(resource.getProject());
                if (javaProject != null) {
                    org.eclipse.jdt.core.search.IJavaSearchScope searchScope = SearchEngine
                            .createJavaSearchScope(new IJavaElement[] { javaProject });
                    SelectionDialog sd = JavaUI.createTypeDialog(getShell(), new ApplicationWindow(getShell()),
                            searchScope, 2, false);
                    sd.open();
                    Object objects[] = sd.getResult();
                    if (objects != null && objects.length > 0) {
                        IType type = (IType) objects[0];
                        String fullyQualifiedName = type.getFullyQualifiedName('.');
                        valueText.setText(type.getFullyQualifiedName());
                        String[] interfaces = type.getSuperInterfaceNames();
                        boolean isList = false;
                        if ("java.lang.Object".equals(fullyQualifiedName)) //$NON-NLS-1$
                            isList = true;
                        else {
                            for (int i = 0; i < interfaces.length; i++) {
                                if (interfaces[i].equals("java.util.Collection") //$NON-NLS-1$
                                        || interfaces[i].equals("java.util.List") //$NON-NLS-1$
                                        || interfaces[i].equals("java.util.Set")) { //$NON-NLS-1$
                                    isList = true;
                                    break;
                                }
                            }
                        }
                        if (isList) {
                            singleBrowse.setEnabled(true);
                            singleLabel.setEnabled(true);
                            singleValueText.setEnabled(true);
                        } else {
                            singleBrowse.setEnabled(false);
                            singleLabel.setEnabled(false);
                            singleValueText.setEnabled(false);
                            singleValueText.setText(""); //$NON-NLS-1$
                        }
                    }
                } else {
                    MessageDialog.openError(getShell(), Messages.ContextValueDialog_JAVA_PROJECT_ERROR,
                            Messages.ContextValueDialog_MUST_BE_JAVA_PROJECT);
                }
            } catch (JavaModelException _ex) {
                Plugin.log(_ex);
            }
        }

        @Override
        public void mouseDoubleClick(MouseEvent mouseevent) {
        }

        @Override
        public void mouseUp(MouseEvent mouseevent) {
        }

    });

    boolean enabled = false;
    if (null != contextValue && null != contextValue.singularClass)
        enabled = true;
    singleLabel = new Label(composite, SWT.NULL);
    singleLabel.setEnabled(enabled);
    singleLabel.setText(Messages.ContextValueDialog_LABEL_LIST_ENTRY_TYPE);
    singleValueText = new Text(composite, SWT.BORDER);
    singleValueText.setEnabled(enabled);
    singleValueText.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 250;
    singleValueText.setLayoutData(gd);
    if (enabled)
        singleValueText.setText(contextValue.singularClass.getName());
    singleBrowse = new Button(composite, 8);
    singleBrowse.setEnabled(enabled);
    singleBrowse.setText(Messages.ContextValueDialog_BUTTON_BROWSE);
    singleBrowse.addMouseListener(new MouseListener() {
        @Override
        public void mouseDown(MouseEvent e) {
            try {
                IJavaProject javaProject = JavaCore.create(resource.getProject());
                if (javaProject != null) {
                    org.eclipse.jdt.core.search.IJavaSearchScope searchScope = SearchEngine
                            .createJavaSearchScope(new IJavaElement[] { javaProject });
                    SelectionDialog sd = JavaUI.createTypeDialog(getShell(), new ApplicationWindow(getShell()),
                            searchScope, 2, false);
                    sd.open();
                    Object objects[] = sd.getResult();
                    if (objects != null && objects.length > 0) {
                        IType type = (IType) objects[0];
                        singleValueText.setText(type.getFullyQualifiedName());
                    }
                } else {
                    MessageDialog.openError(getShell(), Messages.ContextValueDialog_JAVA_PROJECT_ERROR,
                            Messages.ContextValueDialog_MUST_BE_JAVA_PROJECT);
                }
            } catch (JavaModelException _ex) {
                Plugin.log(_ex);
            }
        }

        @Override
        public void mouseDoubleClick(MouseEvent mouseevent) {
        }

        @Override
        public void mouseUp(MouseEvent mouseevent) {
        }

    });
    return parent;
}

From source file:org.jboss.tools.forge.ui.internal.ext.dialog.WizardDialogHelper.java

License:Open Source License

public void openWizard(String windowTitle, UICommand selectedCommand, Map<String, ?> values) {
    Assert.isNotNull(selectedCommand, "No command was selected for execution");
    CommandControllerFactory controllerFactory = FurnaceService.INSTANCE.lookup(CommandControllerFactory.class);
    CommandFactory commandFactory = FurnaceService.INSTANCE.lookup(CommandFactory.class);
    Assert.isNotNull(controllerFactory, CommandControllerFactory.class.getSimpleName() + " service not found");
    Assert.isNotNull(commandFactory, CommandFactory.class.getSimpleName() + " service not found");
    UICommandMetadata metadata = selectedCommand.getMetadata(context);
    Assert.isNotNull(metadata, "No metadata found for " + selectedCommand);
    String commandName = metadata.getName();
    UICommand newCommand = commandFactory.getNewCommandByName(context, commandName);
    if (windowTitle == null) {
        windowTitle = commandName;//  w  w  w. jav a2s  .  co m
    }
    ForgeUIRuntime runtime = new ForgeUIRuntime();
    CommandController controller = controllerFactory.createController(context, runtime, newCommand);
    try {
        controller.initialize();
    } catch (Exception e) {
        ForgeUIPlugin.displayMessage(windowTitle, "Error while initializing controller. Check logs",
                NotificationType.ERROR);
        ForgeUIPlugin.log(e);
        return;
    }
    ForgeWizard wizard = new ForgeWizard(windowTitle, controller, context);
    final WizardDialog wizardDialog;
    if (controller instanceof WizardCommandController) {
        WizardCommandController wizardController = (WizardCommandController) controller;
        if (values != null) {
            Map<String, InputComponent<?, ?>> inputs = wizardController.getInputs();
            for (String key : inputs.keySet()) {
                Object value = values.get(key);
                if (value != null)
                    wizardController.setValueFor(key, value);
            }
            while (wizardController.canMoveToNextStep()) {
                try {
                    wizardController.next().initialize();
                } catch (Exception e) {
                    ForgeUIPlugin.log(e);
                    break;
                }
                inputs = wizardController.getInputs();
                for (String key : inputs.keySet()) {
                    Object value = values.get(key);
                    if (value != null)
                        wizardController.setValueFor(key, value);
                }
            }
            // Rewind
            while (wizardController.canMoveToPreviousStep()) {
                try {
                    wizardController.previous();
                } catch (Exception e) {
                    ForgeUIPlugin.log(e);
                }
            }
        }
        wizardDialog = new ForgeWizardDialog(parentShell, wizard, wizardController);
    } else {
        if (values != null) {
            for (Entry<String, ?> entry : values.entrySet()) {
                controller.setValueFor(entry.getKey(), entry.getValue());
            }
        }
        wizardDialog = new ForgeCommandDialog(parentShell, wizard);
    }
    // TODO: Show help button when it's possible to display the docs for
    // each UICommand
    wizardDialog.setHelpAvailable(false);
    wizardDialog.addPageChangingListener(new IPageChangingListener() {

        @Override
        public void handlePageChanging(PageChangingEvent event) {
            // Mark as unchanged
            ForgeWizardPage currentPage = (ForgeWizardPage) event.getCurrentPage();
            if (currentPage != null) {
                currentPage.setChanged(false);
            }
        }
    });
    wizardDialog.addPageChangedListener(new IPageChangedListener() {
        @Override
        public void pageChanged(PageChangedEvent event) {
            // BEHAVIOR: Finish button is enabled by default and then
            // disabled when any field is selected/changed in the first page

            // WHY: Wizard.canFinish() is called before getNextPage is
            // called, therefore not checking if the second page is complete

            // SOLUTION: Calling updateButtons will call canFinish() once
            // again and set the button to the correct state
            wizardDialog.updateButtons();
        }
    });

    if (controller.getInputs().isEmpty() && controller.canExecute()) {
        try {
            ApplicationWindow window = new ApplicationWindow(parentShell);
            wizard.performFinish(window, parentShell);
        } catch (InvocationTargetException | InterruptedException e) {
            ForgeUIPlugin.log(e);
        }
    } else {
        try {
            wizardDialog.open();
        } catch (Exception e) {
            ForgeUIPlugin.displayMessage("Error", "Error while opening wizard. See Error log",
                    NotificationType.ERROR);
            ForgeUIPlugin.log(e);
        }
    }
}

From source file:org.marketcetera.photon.commons.ui.databinding.RequiredFieldSupportTest.java

@Before
@UI//from  w w  w  . j  a  v a  2s.  c o  m
public void before() {
    mWindow = new ApplicationWindow(null) {
        @Override
        protected Control createContents(Composite parent) {
            DataBindingContext dbc = new DataBindingContext();
            Composite c = new Composite(parent, SWT.NONE);
            Text text = new Text(c, SWT.NONE);
            IObservableValue value = SWTObservables.observeText(text, SWT.Modify);
            RequiredFieldSupport.initFor(dbc, value, "Text", true, null);
            Text hiddenText = new Text(c, SWT.NONE);
            IObservableValue hiddenTextValue = SWTObservables.observeText(hiddenText, SWT.Modify);
            RequiredFieldSupport.initFor(dbc, hiddenTextValue, "HiddenText", false, null);
            ListViewer list = new ListViewer(c);
            list.setContentProvider(new ArrayContentProvider());
            list.setInput(new Object[] { "item 1", "item 2" });
            IViewerObservableList set = ViewersObservables.observeMultiSelection(list);
            RequiredFieldSupport.initFor(dbc, set, "list item", true, null);
            TableViewer table = new TableViewer(c);
            table.setContentProvider(new ArrayContentProvider());
            table.setInput(new Object[] { "item 1", "item 2" });
            IViewerObservableValue single = ViewersObservables.observeSingleSelection(table);
            RequiredFieldSupport.initFor(dbc, single, "table item", true, null);
            GridLayoutFactory.swtDefaults().generateLayout(c);
            return c;
        }
    };
    mWindow.open();
}

From source file:org.marketcetera.photon.internal.strategy.engine.sa.ui.StrategyAgentConnectionCompositeTest.java

private void createAndOpenWindow() throws Exception {
    AbstractUIRunner.syncRun(new ThrowableRunnable() {
        @Override//from   w w  w .java  2  s .  c o m
        public void run() {
            mWindow = new ApplicationWindow(null) {
                @Override
                protected Control createContents(Composite parent) {
                    if (mEngine == null) {
                        mEngine = StrategyAgentEngineFactory.eINSTANCE.createStrategyAgentEngine();
                    }
                    final DataBindingContext dbc = new DataBindingContext();
                    final Composite control = new StrategyAgentConnectionComposite(parent, dbc, mEngine);
                    return control;
                }
            };
            mWindow.open();
        }
    });
}

From source file:org.marketcetera.photon.internal.strategy.engine.ui.DeployedStrategyConfigurationCompositeTest.java

private void createAndOpenWindow() throws Exception {
    AbstractUIRunner.syncRun(new ThrowableRunnable() {
        @Override/*from   w w w  .java2 s  .  c o m*/
        public void run() {
            mWindow = new ApplicationWindow(null) {
                @Override
                protected Control createContents(Composite parent) {
                    if (mStrategy == null) {
                        mStrategy = StrategyEngineCoreFactory.eINSTANCE.createDeployedStrategy();
                    }
                    final DataBindingContext dbc = new DataBindingContext();
                    final Composite control = new DeployedStrategyConfigurationComposite(parent, dbc,
                            mStrategy);
                    return control;
                }
            };
            mWindow.open();
        }
    });
}

From source file:org.marketcetera.photon.internal.strategy.engine.ui.DeployStrategyCompositeTest.java

private void createAndOpenWindow() {
    mWindow = new ApplicationWindow(null) {
        @Override//from w ww.  java2s  .  c o  m
        protected Control createContents(Composite parent) {
            final DataBindingContext dbc = new DataBindingContext();
            final Composite control = new DeployStrategyComposite(parent, dbc, mStrategy, mAvailableEngines,
                    mEngine, mMockSelectionButton);
            return control;
        }
    };
    mWindow.open();
}