Example usage for org.eclipse.jdt.internal.core PackageFragment getElementName

List of usage examples for org.eclipse.jdt.internal.core PackageFragment getElementName

Introduction

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

Prototype

@Override
    public String getElementName() 

Source Link

Usage

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

License:Open Source License

/**
 * @param resource//  w  ww  .  j ava 2 s. c o m
 *            resource
 * @param newDestination
 *            the new destination
 * @return
 */
public static String getNewDestinationFullyQualifiedName(final IResource resource,
        final String newDestination) {
    // TODO Auto-generated method stub
    String projectRelativeDestination = "F/" + resource.getProject().getName();
    IJavaElement e = JavaCore.create(
            resource.getProject().getFolder(newDestination.replaceFirst(projectRelativeDestination, "")));
    if (e != null && e instanceof PackageFragment) {
        PackageFragment p = (PackageFragment) e;
        return p.getElementName() + "." + resource.getName().replaceAll(".java", "");
    } else if (e != null && e instanceof IPackageFragmentRoot) {
        return resource.getName();
    } else {
        return "bla";
    }
}

From source file:com.hudson.hibernatesynchronizer.dialog.TemplateGenerationDialog.java

License:GNU General Public License

private void handleBrowse() {

    try {/*from w  ww.j a  va 2  s.  co m*/
        String templateName = templatesCBO.getItem(templatesCBO.getSelectionIndex());
        template = TemplateManager.getInstance().findTemplateByName(templateName);
        if (null != template) {
            if (template.isJavaClass()) {
                SelectionDialog sd = JavaUI.createPackageDialog(getShell(), project,
                        IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);
                sd.open();
                Object[] objects = sd.getResult();
                if (null != objects && objects.length > 0) {
                    PackageFragment pf = (PackageFragment) objects[0];
                    containerText.setText(pf.getElementName());
                }
            } else {
                ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(),
                        ResourcesPlugin.getWorkspace().getRoot(), false, "Select new file container");
                if (dialog.open() == ContainerSelectionDialog.OK) {
                    Object[] result = dialog.getResult();
                    if (result.length == 1) {
                        containerText.setText(((IPath) result[0]).toOSString());
                    }
                }
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
    }
}

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

License:GNU General Public License

protected Control createDialogArea(Composite parent) {

    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout(3, false);
    composite.setLayout(layout);/*w w  w  .j a  v a 2 s .c  o m*/

    try {
        Label label = new Label(composite, SWT.NULL);
        label.setText("Template:");
        templatesCBO = new Combo(composite, SWT.READ_ONLY);
        List templates = TemplateManager.getInstance().getTemplates();
        int templateCount = 0;
        if (null != templates && templates.size() > 0) {
            for (Iterator i = templates.iterator(); i.hasNext();) {
                Template template = (Template) i.next();
                if (null == TemplateManager.getInstance().findProjectTemplate(project, template.getId())) {
                    templateCount++;
                    templatesCBO.add(template.getName());
                }
            }
            if (templateCount > 0) {
                templatesCBO.select(0);
            }
        }
        GridData gd = new GridData();
        gd.horizontalSpan = 2;
        gd.grabExcessHorizontalSpace = true;
        templatesCBO.setLayoutData(gd);
        templatesCBO.addSelectionListener(new SelectionListener() {
            public void widgetSelected(SelectionEvent e) {
                try {
                    String templateName = templatesCBO.getItem(templatesCBO.getSelectionIndex());
                    Template template = TemplateManager.getInstance().findTemplateByName(templateName);
                    if (null != template) {
                        String newLabel = null;
                        String newName = null;
                        if (template.isJavaClass()) {
                            newLabel = "Package:";
                            newName = "Name:";
                        } else {
                            newLabel = "Location:";
                            newName = "Name:";
                        }
                        if (!newLabel.equals(locationLBL.getText())) {
                            locationTXT.setText("");
                            locationLBL.setText(newLabel);
                            resourceNameLBL.setText(newName);
                        }
                    }
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }

            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        String templateName = templatesCBO.getItem(templatesCBO.getSelectionIndex());
        Template template = TemplateManager.getInstance().findTemplateByName(templateName);

        label = new Label(composite, SWT.NULL);
        gd = new GridData();
        gd.horizontalSpan = 3;
        gd.grabExcessHorizontalSpace = true;
        label.setLayoutData(gd);
        label.setText("Tip: you can use Velocity variables in the fields below.");

        resourceNameLBL = new Label(composite, SWT.NULL);
        if (template.isJavaClass())
            resourceNameLBL.setText("Name:");
        else
            resourceNameLBL.setText("Name:");
        nameTXT = new Text(composite, SWT.BORDER);
        gd = new GridData();
        gd.horizontalSpan = 2;
        gd.grabExcessHorizontalSpace = true;
        gd.widthHint = 200;
        nameTXT.setLayoutData(gd);
        nameTXT.setLayoutData(gd);

        locationLBL = new Label(composite, SWT.NULL);
        if (template.isJavaClass())
            locationLBL.setText("Package:");
        else
            locationLBL.setText("Location:");
        locationTXT = new Text(composite, SWT.BORDER);
        gd = new GridData();
        gd.widthHint = 200;
        locationTXT.setLayoutData(gd);
        locationSearchBTN = new Button(composite, SWT.NATIVE);
        locationSearchBTN.setText("Browse");
        gd = new GridData();
        locationSearchBTN.setLayoutData(gd);
        locationSearchBTN.addSelectionListener(new SelectionListener() {
            public void widgetSelected(SelectionEvent e) {
                try {
                    String templateName = templatesCBO.getItem(templatesCBO.getSelectionIndex());
                    Template template = TemplateManager.getInstance().findTemplateByName(templateName);
                    if (null != template) {
                        if (template.isJavaClass()) {
                            IJavaProject javaProject = JavaCore.create(project);
                            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];
                                locationTXT.setText(pf.getElementName());
                            }
                        } else {
                            ContainerSelectionDialog d = new ContainerSelectionDialog(getShell(), project,
                                    false, "Resource location selection");
                            d.open();
                            Object[] arr = d.getResult();
                            StringBuffer sb = new StringBuffer();
                            for (int i = 0; i < arr.length; i++) {
                                Path path = (Path) arr[i];
                                for (int j = 0; j < path.segments().length; j++) {
                                    if (j == 0) {
                                        if (!path.segments()[j].equals(project.getName())) {
                                            MessageDialog.openError(getParentShell(), "Location Error",
                                                    "You may only choose a location in the current project");
                                            return;
                                        }
                                    } else {
                                        sb.append("/");
                                        sb.append(path.segments()[j]);
                                    }
                                }
                                locationTXT.setText(sb.toString());
                            }
                        }
                    }
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }

            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        MessageDialog.openError(parent.getShell(), "An error has occured", e.getMessage());
    }

    new Label(composite, SWT.NULL);
    Composite subComp = new Composite(composite, SWT.NULL);
    overwrite = new BooleanFieldEditor("TemplateOverwrite", "Overwrite if a resource/class already exists",
            subComp);
    overwrite.setPreferenceStore(store);

    return parent;
}

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

License:GNU General Public License

protected Control createDialogArea(Composite parent) {

    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout(3, false);
    composite.setLayout(layout);//from   w  ww.j a  va 2s. c  o  m

    try {
        Label label = new Label(composite, SWT.NULL);
        label.setText("Template:");
        label = new Label(composite, SWT.NULL);
        label.setText(projectTemplate.getTemplate().getName());
        GridData gd = new GridData();
        gd.horizontalSpan = 2;
        gd.grabExcessHorizontalSpace = true;
        label.setLayoutData(gd);

        label = new Label(composite, SWT.NULL);
        gd = new GridData();
        gd.horizontalSpan = 3;
        gd.grabExcessHorizontalSpace = true;
        label.setLayoutData(gd);
        label.setText("Tip: you can use Velocity variables in the fields below.");

        resourceNameLBL = new Label(composite, SWT.NULL);
        if (projectTemplate.getTemplate().isJavaClass())
            resourceNameLBL.setText("Name:");
        else
            resourceNameLBL.setText("Name:");
        nameTXT = new Text(composite, SWT.BORDER);
        nameTXT.setText(projectTemplate.getName());
        gd = new GridData();
        gd.horizontalSpan = 2;
        gd.widthHint = 200;
        gd.grabExcessHorizontalSpace = true;
        nameTXT.setLayoutData(gd);

        locationLBL = new Label(composite, SWT.NULL);
        if (projectTemplate.getTemplate().isJavaClass())
            locationLBL.setText("Package:");
        else
            locationLBL.setText("Location:");
        locationTXT = new Text(composite, SWT.BORDER);
        locationTXT.setText(projectTemplate.getLocation());
        gd = new GridData();
        gd.widthHint = 200;
        locationTXT.setLayoutData(gd);
        locationSearchBTN = new Button(composite, SWT.NATIVE);
        locationSearchBTN.setText("Browse");
        gd = new GridData();
        locationSearchBTN.setLayoutData(gd);
        locationSearchBTN.addSelectionListener(new SelectionListener() {
            public void widgetSelected(SelectionEvent e) {
                try {
                    if (projectTemplate.getTemplate().isJavaClass()) {
                        IJavaProject javaProject = JavaCore.create(project);
                        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];
                            locationTXT.setText(pf.getElementName());
                        }
                    } else {
                        ContainerSelectionDialog d = new ContainerSelectionDialog(getShell(), project, false,
                                "Resource location selection");
                        d.open();
                        Object[] arr = d.getResult();
                        StringBuffer sb = new StringBuffer();
                        for (int i = 0; i < arr.length; i++) {
                            Path path = (Path) arr[i];
                            for (int j = 0; j < path.segments().length; j++) {
                                if (j == 0) {
                                    if (!path.segments()[j].equals(project.getName())) {
                                        MessageDialog.openError(getParentShell(), "Location Error",
                                                "You may only choose a location in the current project");
                                        return;
                                    }
                                } else {
                                    sb.append("/");
                                    sb.append(path.segments()[j]);
                                }
                            }
                            locationTXT.setText(sb.toString());
                        }
                    }
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }

            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        MessageDialog.openError(parent.getShell(), "An error has occured", e.getMessage());
    }

    IPreferenceStore store = new PreferenceStore();
    store.setValue("TemplateOverwrite", projectTemplate.shouldOverride());
    new Label(composite, SWT.NULL);
    Composite subComp = new Composite(composite, SWT.NULL);
    overwrite = new BooleanFieldEditor("TemplateOverwrite", "Overwrite if a resource/class already exists",
            subComp);
    overwrite.setPreferenceStore(store);
    overwrite.load();

    return parent;
}

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;//from   ww  w .j a  v a  2s .c o m
    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:net.harawata.mybatipse.mybatis.XmlCompletionProposalComputer.java

License:Open Source License

private void proposePackage(final ContentAssistRequest contentAssistRequest, IJavaProject project,
        String matchString, final int start, final int length) throws CoreException {
    final List<ICompletionProposal> results = new ArrayList<ICompletionProposal>();
    final Set<String> foundPkgs = new HashSet<String>();
    int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
    // Include application libraries only when package is specified (for better performance).
    boolean pkgSpecified = matchString != null && matchString.indexOf('.') > 0;
    if (pkgSpecified)
        includeMask |= IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES;
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] { project }, includeMask);
    SearchRequestor requestor = new SearchRequestor() {
        @Override//from  w  w w .  j a  v  a2  s. c o m
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            PackageFragment element = (PackageFragment) match.getElement();
            String pkg = element.getElementName();
            if (pkg != null && pkg.length() > 0 && !foundPkgs.contains(pkg)) {
                foundPkgs.add(pkg);
                results.add(new CompletionProposal(pkg, start, length, pkg.length(), Activator.getIcon(), pkg,
                        null, null));
            }
        }
    };
    searchPackage(matchString, scope, requestor);
    addProposals(contentAssistRequest, results);
}

From source file:sidecarviz.core.MonitorEclipse.java

License:BSD License

/**
 * When the developer selects an item in the package explorer, we monitor it and save the item in a
 * hashmap for later access./*from w ww.  j  av a  2  s  .  c  om*/
 * 
 * @param selection
 */
public void gotPackageExplorerSelectionChanged(TreeSelection selection) {
    // if we cast it to a string, the selection is between two brackets [....]
    // the stuff after the selection gives us more information
    Object[] selected = selection.toArray();
    for (Object o : selected) {
        Class<?> selectedItemType = o.getClass();
        if (selectedItemType.equals(PackageFragment.class)) {
            PackageFragment frag = (PackageFragment) o;
            String fragName = frag.getElementName();

            DebugUtils.println("Package: " + fragName);
            // store the element in a hashmap, for later access
            packageExplorerSelectedPackages.put(fragName, frag);

            // TODO: forward to Flash
        } else if (selectedItemType.equals(CompilationUnit.class)) {
            CompilationUnit comp = (CompilationUnit) o;
            String compName = comp.getElementName();
            IPath compPath = comp.getPath();

            DebugUtils.println("Class: " + compName + "   " + compPath);
            // store the element in a hashmap, for later access
            packageExplorerSelectedClasses.put(compName, comp);

            // TODO: forward to Flash
        } else {
            // DebugUtils.println(o.getClass());
            // unhandled
        }
    }
}