Example usage for org.eclipse.jdt.core IPackageFragmentRoot getJavaProject

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getJavaProject

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot getJavaProject.

Prototype

IJavaProject getJavaProject();

Source Link

Document

Returns the Java project this element is contained in, or null if this element is not contained in any Java project (for instance, the IJavaModel is not contained in any Java project).

Usage

From source file:com.hudson.hibernatesynchronizer.util.SynchronizerThread.java

License:GNU General Public License

static boolean synchronizeClass(HibernateClass hc, IPackageFragmentRoot root, boolean boEnabled,
        boolean managersEnabled, boolean customEnabled, IProgressMonitor monitor, String currentFileName,
        IFile syncFile, Context context, boolean force) {
    context.put("class", hc);
    try {//ww  w .  ja  v a  2  s.  c o m
        Snippet snippet = TemplateManager.getInstance().findSnippetByName("ClassSetup",
                root.getJavaProject().getProject());
        if (null != snippet) {
            StringWriter sw = new StringWriter();
            Constants.customGenerator.evaluate(context, sw, Velocity.class.getName(), snippet.getContent());
            String trimmed = sw.toString().trim();
            if (trimmed.startsWith(WARNING)) {
                String message = trimmed.substring(WARNING.length(), trimmed.length());
                if (null != syncFile) {
                    String key = WARNING + syncFile.getName() + message;
                    if (null == context.get(key)) {
                        context.put(key, Boolean.TRUE);
                        EditorUtil.addWarningMarker(syncFile, message, 0);
                    }
                }
            } else if (trimmed.startsWith(ERROR)) {
                String message = trimmed.substring(ERROR.length(), trimmed.length());
                if (null != syncFile) {
                    String key = ERROR + syncFile.getName() + message;
                    if (null == context.get(key)) {
                        context.put(key, Boolean.TRUE);
                        EditorUtil.addProblemMarker(syncFile, message, 0);
                    }
                }
            } else if (trimmed.startsWith(FATAL)) {
                String message = trimmed.substring(FATAL.length(), trimmed.length());
                if (null != syncFile) {
                    String key = FATAL + syncFile.getName() + message;
                    if (null == context.get(key)) {
                        context.put(key, Boolean.TRUE);
                        EditorUtil.addProblemMarker(syncFile, message, 0);
                    }
                }
                return false;
            }
        }
    } catch (Exception e) {
    }

    try {
        if (boEnabled) {
            if (null != monitor)
                monitor.subTask(currentFileName + ": generating base business object");
            writeClass("BaseClass.vm", context, root, hc.getBasePackageName(), hc.getBaseClassName(), true);
            if (null != monitor)
                monitor.worked(1);
            if (null != monitor)
                monitor.subTask(currentFileName + ": generating extension business object");
            writeExtensionClass("Class.vm", "ClassConstructor.vm", context, root, hc.getPackageName(),
                    hc.getClassName());
            if (hc.hasProxy())
                writeProxyClass("ClassProxy.vm", "ClassProxyContents.vm", context, root,
                        hc.getProxyPackageName(), hc.getProxyClassName());

            if (null != monitor)
                monitor.worked(1);

            // subclasses
            if (null != monitor)
                monitor.subTask(currentFileName + ": generating subclasses");
            if (hc.getSubclassList().size() > 0) {
                for (Iterator i2 = hc.getSubclassList().iterator(); i2.hasNext();) {
                    HibernateClass subclass = (HibernateClass) i2.next();
                    if (synchronizeClass(subclass, root, boEnabled, managersEnabled, customEnabled, monitor,
                            currentFileName, syncFile, context, force))
                        return true;
                }
                context.put("class", hc);
            }
            if (null != monitor)
                monitor.worked(1);

            // class components
            if (null != monitor)
                monitor.subTask(currentFileName + ": generating components");
            for (Iterator iter = hc.getComponentList().iterator(); iter.hasNext();) {
                HibernateComponentClass chc = (HibernateComponentClass) iter.next();
                if (!chc.isDynamic()) {
                    context.put("class", chc);
                    writeClass("BaseClass.vm", context, root, chc.getBasePackageName(), chc.getBaseClassName(),
                            true);
                    writeExtensionClass("Class.vm", "ClassConstructor.vm", context, root, chc.getPackageName(),
                            chc.getClassName());
                }
            }
            for (Iterator i = hc.getCollectionList().iterator(); i.hasNext();) {
                for (Iterator i2 = ((HibernateClassCollectionProperty) i.next()).getCompositeList()
                        .iterator(); i2.hasNext();) {
                    HibernateComponentClass chc = (HibernateComponentClass) i2.next();
                    context.put("class", chc);
                    writeClass("BaseClass.vm", context, root, chc.getBasePackageName(), chc.getBaseClassName(),
                            true);
                    writeExtensionClass("Class.vm", "ClassConstructor.vm", context, root, chc.getPackageName(),
                            chc.getClassName());
                }
            }
            if (null != monitor)
                monitor.worked(1);
            context.put("class", hc);
            // composite id
            if (null != monitor)
                monitor.subTask(currentFileName + ": generating id");
            if (null != hc.getId() && hc.getId().isComposite() && hc.getId().hasExternalClass()) {
                writeExtensionClass("ClassPK.vm", "PKConstructor.vm", context, root,
                        hc.getId().getProperty().getPackageName(), hc.getId().getProperty().getClassName());
                writeClass("BaseClassPK.vm", context, root, hc.getBasePackageName(),
                        "Base" + hc.getId().getProperty().getClassName(), true);
            }
            if (null != monitor)
                monitor.worked(1);
            // enumeration
            if (null != monitor)
                monitor.subTask(currentFileName + ": generating enumerations");
            for (Iterator i2 = hc.getProperties().iterator(); i2.hasNext();) {
                HibernateClassProperty prop = (HibernateClassProperty) i2.next();
                if (prop.isEnumeration()) {
                    context.put("field", prop);
                    writeClass("Enumeration.vm", context, root, prop.getPackageName(), prop.getClassName(),
                            false);
                }
            }
            if (null != monitor)
                monitor.worked(1);
        } else if (null != monitor)
            monitor.worked(6);
        if (managersEnabled && hc.canMakeDAO()) {
            context.put("class", hc);
            if (null != monitor)
                monitor.subTask(currentFileName + ": generating root DAO");
            if (!hc.usesCustomDAO()) {
                writeClass("BaseRootDAO.vm", context, root, hc.getBaseDAOPackageName(),
                        hc.getBaseRootDAOClassName(), true);
            }
            writeClass("RootDAO.vm", context, root, hc.getRootDAOPackageName(), hc.getRootDAOClassName(),
                    false);
            if (null != monitor)
                monitor.worked(1);
            if (null != monitor)
                monitor.subTask(currentFileName + ": generating base DAO");
            if (null != monitor)
                monitor.worked(1);
            writeClass("BaseDAO.vm", context, root, hc.getBaseDAOPackageName(), hc.getBaseDAOClassName(), true);
            if (null != monitor)
                monitor.worked(1);
            if (null != monitor)
                monitor.subTask(currentFileName + ": generating extension DAO");
            writeClass("DAO.vm", context, root, hc.getDAOPackageName(), hc.getDAOClassName(), false);
            if (null != monitor)
                monitor.worked(1);
        } else if (null != monitor)
            monitor.worked(3);
        if (customEnabled) {
            List templates = TemplateManager.getInstance()
                    .getProjectTemplates(root.getJavaProject().getProject());
            for (Iterator iter = templates.iterator(); iter.hasNext();) {
                ProjectTemplate projectTemplate = (ProjectTemplate) iter.next();
                if (writeCustom(root.getJavaProject().getProject(), root, projectTemplate, hc, context,
                        syncFile, force))
                    return true;
            }
        }
    } catch (Exception e) {
        Plugin.logError(e);
    }
    return false;
}

From source file:com.hudson.hibernatesynchronizer.util.SynchronizerThread.java

License:GNU General Public License

public static void removeReferences(String currentFileName, HibernateClass hc, IPackageFragmentRoot root,
        IProgressMonitor monitor) {//from  ww  w  .j  av a2 s .  c o  m
    Context context = getDefaultContext(hc, root.getJavaProject(), null);
    try {
        Snippet snippet = TemplateManager.getInstance().findSnippetByName("Setup",
                root.getJavaProject().getProject());
        if (null != snippet) {
            StringWriter sw = new StringWriter();
            Constants.customGenerator.evaluate(context, sw, Velocity.class.getName(), snippet.getContent());
        }
    } catch (Exception e) {
    }
    if (null != monitor)
        monitor.subTask(currentFileName + ": removing base business object");
    removeClass(root, hc.getBasePackageName(), hc.getBaseClassName());
    if (null != monitor)
        monitor.worked(1);
    if (null != monitor)
        monitor.subTask(currentFileName + ": removing extension business object");
    removeClass(root, hc.getPackageName(), hc.getClassName());
    if (hc.hasProxy())
        removeClass(root, hc.getProxyPackageName(), hc.getProxyClassName());
    if (null != monitor)
        monitor.worked(1);

    // subclasses
    if (null != monitor)
        monitor.subTask(currentFileName + ": removing subclasses");
    if (hc.getSubclassList().size() > 0) {
        for (Iterator i2 = hc.getSubclassList().iterator(); i2.hasNext();) {
            HibernateClass subclass = (HibernateClass) i2.next();
            removeReferences(currentFileName, subclass, root, monitor);
        }
    }
    if (null != monitor)
        monitor.worked(1);

    // class components
    if (null != monitor)
        monitor.subTask(currentFileName + ": removing components");
    for (Iterator iter = hc.getComponentList().iterator(); iter.hasNext();) {
        HibernateComponentClass chc = (HibernateComponentClass) iter.next();
        removeClass(root, chc.getBasePackageName(), chc.getBaseClassName());
        removeClass(root, chc.getPackageName(), chc.getClassName());
    }
    if (null != monitor)
        monitor.worked(1);
    context.put("class", hc);
    // composite id
    if (null != monitor)
        monitor.subTask(currentFileName + ": removing id");
    if (null != hc.getId() && hc.getId().isComposite()) {
        removeClass(root, hc.getId().getProperty().getPackageName(), hc.getId().getProperty().getClassName());
        removeClass(root, hc.getBasePackageName(), "Base" + hc.getId().getProperty().getClassName());
    }
    if (null != monitor)
        monitor.worked(1);
    // enumeration
    if (null != monitor)
        monitor.subTask(currentFileName + ": removing enumerations");
    for (Iterator i2 = hc.getProperties().iterator(); i2.hasNext();) {
        HibernateClassProperty prop = (HibernateClassProperty) i2.next();
        if (prop.isEnumeration()) {
            removeClass(root, prop.getPackageName(), prop.getClassName());
        }
    }
    if (null != monitor)
        monitor.worked(1);

    if (null != monitor)
        monitor.subTask(currentFileName + ": removing base DAO");
    if (null != monitor)
        monitor.worked(1);
    removeClass(root, hc.getBaseDAOPackageName(), hc.getBaseDAOClassName());
    if (null != monitor)
        monitor.worked(1);
    if (null != monitor)
        monitor.subTask(currentFileName + ": removing extension DAO");
    removeClass(root, hc.getDAOPackageName(), hc.getDAOClassName());
    if (null != monitor)
        monitor.worked(1);

    try {
        List templates = TemplateManager.getInstance().getProjectTemplates(root.getJavaProject().getProject());
        for (Iterator iter = templates.iterator(); iter.hasNext();) {
            ProjectTemplate projectTemplate = (ProjectTemplate) iter.next();
            removeCustom(root.getJavaProject().getProject(), root, projectTemplate, hc, context);
        }
    } catch (CoreException ce) {
    }
}

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

License:GNU General Public License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *///w  w w . ja  v a  2 s  .  c om

private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() == 1) {
            Object obj = ssel.getFirstElement();
            if (obj instanceof IResource) {
                IContainer cont;
                if (obj instanceof IContainer)
                    cont = (IContainer) obj;
                else
                    cont = ((IResource) obj).getParent();
                containerText.setText(cont.getFullPath().toString());
                projectChanged(((IResource) obj).getProject());
            } else if (obj instanceof IPackageFragment) {
                IPackageFragment frag = (IPackageFragment) obj;
                containerText.setText(frag.getPath().toString());
                projectChanged(frag.getJavaProject().getProject());
            } else if (obj instanceof IPackageFragmentRoot) {
                IPackageFragmentRoot root = (IPackageFragmentRoot) obj;
                containerText.setText(root.getPath().toString());
                projectChanged(root.getJavaProject().getProject());
            } else if (obj instanceof IJavaProject) {
                IJavaProject proj = (IJavaProject) obj;
                containerText.setText("/" + proj.getProject().getName());
                projectChanged(proj.getProject());
            } else if (obj instanceof IProject) {
                IProject proj = (IProject) obj;
                containerText.setText("/" + proj.getName());
                projectChanged(proj);
            }
        }
    }
    fileText.setText("hibernate.cfg.xml");
}

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

License:GNU General Public License

public Composite addConfiguration(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);/*from   w ww . j  a v a2s .  c om*/
    layout.numColumns = 3;
    layout.verticalSpacing = 9;

    Label label = new Label(container, SWT.NULL);
    label.setText("&Container:");

    containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
    containerText.setEnabled(false);
    containerText.setBackground(new Color(null, 255, 255, 255));
    GridData gd = new GridData();
    gd.widthHint = 250;
    containerText.setLayoutData(gd);
    containerText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    Button containerButton = new Button(container, SWT.NATIVE);
    containerButton.setText("Browse");
    containerButton.addMouseListener(new ContainerMouseListener(this));

    label = new Label(container, SWT.NULL);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 3;
    label.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Driver:");
    driverText = new Text(container, SWT.BORDER | SWT.SINGLE);
    driverText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    driverText.setEnabled(false);
    driverText.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData();
    gd.widthHint = 250;
    driverText.setLayoutData(gd);
    Button driverButton = new Button(container, SWT.NATIVE);
    driverButton.setText("Browse");
    driverButton.addMouseListener(new DriverMouseListener(this));

    label = new Label(container, SWT.NULL);
    label.setText("&Database URL:");
    databaseUrlText = new Text(container, SWT.BORDER | SWT.SINGLE);
    databaseUrlText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 250;
    databaseUrlText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Username:");
    usernameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    usernameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 150;
    usernameText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Password:");
    passwordText = new Text(container, SWT.BORDER | SWT.SINGLE);
    passwordText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    passwordText.setEchoChar('*');
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 150;
    passwordText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("Table pattern:");
    tablePattern = new Text(container, SWT.BORDER | SWT.SINGLE);
    tablePattern.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    tablePattern.setEnabled(true);
    tablePattern.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 250;
    tablePattern.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("Schema pattern:");
    schemaPattern = new Text(container, SWT.BORDER | SWT.SINGLE);
    schemaPattern.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    schemaPattern.setEnabled(true);
    schemaPattern.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 250;
    schemaPattern.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("Tables");
    table = new Table(container, SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.CHECK);
    table.setVisible(true);
    table.setLinesVisible(false);
    table.setHeaderVisible(false);
    table.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            dialogChanged();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    GridData data = new GridData();
    data.heightHint = 150;
    data.widthHint = 250;
    table.setLayoutData(data);

    // create the columns
    TableColumn nameColumn = new TableColumn(table, SWT.LEFT);
    ColumnLayoutData nameColumnLayout = new ColumnWeightData(100, false);

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

    Composite buttonContainer = new Composite(container, SWT.NULL);
    buttonContainer.setLayout(new GridLayout(1, true));
    gd = new GridData();
    gd.verticalAlignment = GridData.BEGINNING;
    gd.horizontalAlignment = GridData.BEGINNING;
    buttonContainer.setLayoutData(gd);
    tableRefreshButton = new Button(buttonContainer, SWT.PUSH);
    tableRefreshButton.setText("Refresh");
    tableRefreshButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tableRefreshButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            try {
                dialog.run(false, true, new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        try {
                            monitor.beginTask("Refreshing tables...", 21);
                            refreshTables(monitor);
                        } catch (Exception e) {
                            throw new InvocationTargetException(e);
                        } finally {
                            monitor.done();
                        }
                    }
                });
            } catch (Exception exc) {
            }
        }
    });
    selectAllButton = new Button(buttonContainer, SWT.PUSH);
    selectAllButton.setText("Select All");
    selectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    selectAllButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {
                for (int i = 0; i < table.getItemCount(); i++) {
                    table.getItem(i).setChecked(true);
                }
                dialogChanged();
            } catch (Exception exc) {
            }
        }
    });
    selectNoneButton = new Button(buttonContainer, SWT.PUSH);
    selectNoneButton.setText("Select None");
    selectNoneButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    selectNoneButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {
                for (int i = 0; i < table.getItemCount(); i++) {
                    table.getItem(i).setChecked(false);
                }
                dialogChanged();
            } catch (Exception exc) {
            }
        }
    });

    label = new Label(container, SWT.NULL);
    label.setText("&Package:");
    packageText = new Text(container, SWT.BORDER | SWT.SINGLE);
    packageText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    gd = new GridData();
    gd.widthHint = 250;
    packageText.setLayoutData(gd);

    packageButton = new Button(container, SWT.NATIVE);
    packageButton.setText("Browse");
    packageButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            if (null != project) {
                try {
                    IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
                    SelectionDialog sd = JavaUI.createPackageDialog(getShell(), project,
                            IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);
                    sd.open();
                    Object[] objects = sd.getResult();
                    if (null != objects && objects.length > 0) {
                        IPackageFragment pf = (IPackageFragment) objects[0];
                        packageText.setText(pf.getElementName());
                    }
                } catch (JavaModelException jme) {
                    jme.printStackTrace();
                }
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });

    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() == 1) {
            Object obj = ssel.getFirstElement();
            if (obj instanceof IResource) {
                IContainer cont;
                if (obj instanceof IContainer)
                    cont = (IContainer) obj;
                else
                    cont = ((IResource) obj).getParent();
                containerText.setText(cont.getFullPath().toString());
                projectChanged(cont.getProject());
            } else if (obj instanceof IPackageFragment) {
                IPackageFragment frag = (IPackageFragment) obj;
                containerText.setText(frag.getPath().toString());
                projectChanged(frag.getJavaProject().getProject());
            } else if (obj instanceof IPackageFragmentRoot) {
                IPackageFragmentRoot root = (IPackageFragmentRoot) obj;
                containerText.setText(root.getPath().toString());
                projectChanged(root.getJavaProject().getProject());
            } else if (obj instanceof IJavaProject) {
                IJavaProject proj = (IJavaProject) obj;
                containerText.setText("/" + proj.getProject().getName());
                projectChanged(proj.getProject());
            } else if (obj instanceof IProject) {
                IProject proj = (IProject) obj;
                containerText.setText("/" + proj.getName());
                projectChanged(proj);
            }
        }
    }

    containerText.forceFocus();
    initialize();
    dialogChanged();
    return container;
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.ApplicationServletClassDialog.java

License:Mozilla Public License

private IStatus hasTapestryServletClassAsSuperType(String superclassName, IPackageFragmentRoot root) {
    SpindleStatus status = new SpindleStatus();
    enableButton(root == null);/*w  w w . ja  v a2s. c  om*/
    if (root == null) {
        return status;
    }
    String superclassBaseTypeName = UIPlugin.getString("TapestryEngine.defaultServlet");
    if (superclassBaseTypeName == null) {
        throw new Error("tapestry servlet type: " + superclassBaseTypeName + " does not exist in properties!");
    }
    if (!superclassName.equals(superclassBaseTypeName)) {
        try {
            IType chosenSuperclassType = resolveTypeName(root.getJavaProject(), superclassName);
            if (chosenSuperclassType == null) {
                status.setWarning(UIPlugin.getString(name + ".warning.TypeNotExists", superclassName));
                return status;
            }
            boolean isBinary = chosenSuperclassType.isBinary();
            IType superclassBaseType = resolveTypeName(root.getJavaProject(), superclassBaseTypeName);
            if (superclassBaseType == null || !superclassBaseType.exists()) {
                status.setError(UIPlugin.getString(name + ".warning.TypeNotExists", superclassBaseTypeName));
                return status;
            }
            boolean match = false;
            ITypeHierarchy hierarchy = chosenSuperclassType.newSupertypeHierarchy(null);
            if (hierarchy.exists()) {
                IType[] superClasses = hierarchy.getAllSupertypes(chosenSuperclassType);
                for (int i = 0; i < superClasses.length; i++) {
                    if (superClasses[i].equals(superclassBaseType)) {
                        match = true;
                    }
                }
            }
            if (!match) {
                status.setError(
                        UIPlugin.getString(name + ".warning.SuperclassClassNotExtend", superclassBaseTypeName));
                return status;
            }

        } catch (JavaModelException e) {
            status.setError(name + ".error.couldn't.do.it");
        }
    }
    return status;
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.EngineClassDialog.java

License:Mozilla Public License

protected IStatus typeChanged() {

    SpindleStatus status = new SpindleStatus();

    String engineClassname = getTextValue();
    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();

    enableButton(root != null);/*from  w w  w  . j  a va2s.c o m*/
    chosenType = null;
    if (root == null || engineClassname == null || "".equals(engineClassname)) {
        status.setError(UIPlugin.getString(name + ".warning.TypeNotExists", "'empty string'"));
        return status;
    }
    try {
        IType engineType = resolveTypeName(root.getJavaProject(), engineClassname);
        if (engineType == null) {
            status.setError(UIPlugin.getString(name + ".warning.TypeNotExists", engineClassname));
            return status;
        }
        boolean isBinary = engineType.isBinary();
        String engineBaseTypeName = UIPlugin.getString("TapestryEngine.classname");
        if (engineBaseTypeName == null) {
            throw new Error(
                    "tapestry engine base type: " + engineBaseTypeName + " does not exist in properties!");
        }
        IType engineBaseType = resolveTypeName(root.getJavaProject(), engineBaseTypeName);
        if (engineBaseType == null || !engineBaseType.exists()) {
            status.setError(UIPlugin.getString(name + ".warning.EngineBaseTypeNotExists", engineBaseTypeName));
            return status;
        }
        boolean match = false;
        if (engineBaseType.isInterface()) {
            String[] superInterfaces = engineType.getSuperInterfaceNames();
            if (superInterfaces != null && superInterfaces.length > 0) {
                for (int i = 0; i < superInterfaces.length; i++) {
                    if (isBinary && engineBaseTypeName.endsWith(superInterfaces[i])) {
                        match = true;
                    } else {
                        match = engineBaseTypeName.equals(superInterfaces[i]);
                    }
                }
            } else {
                match = false;
            }
            if (!match) {
                status.setWarning(UIPlugin.getString(name + ".warning.EngineDoesNotImplementInterface",
                        engineBaseTypeName));
                return status;
            }
        } else {
            ITypeHierarchy hierarchy = engineType.newSupertypeHierarchy(null);
            if (hierarchy.exists()) {
                IType[] superClasses = hierarchy.getAllSupertypes(engineType);
                for (int i = 0; i < superClasses.length; i++) {
                    if (superClasses[i].equals(engineBaseType)) {
                        match = true;
                    }
                }
            }
            if (!match) {
                if (!canFindJavaxServletJar(root.getJavaProject())) {
                    status.setError(UIPlugin.getString(name + ".error.javax.servlet.jar.NOTFOUND"));
                } else {
                    status.setError(
                            UIPlugin.getString(name + ".warning.EngineClassNotExtend", engineBaseTypeName));
                }
                return status;
            }
            chosenType = engineType;
        }

    } catch (JavaModelException e) {
        status.setError(name + ".error.couldn't.do.it");
    }

    return status;

}

From source file:com.iw.plugins.spindle.ui.wizards.fields.InterfaceChooser.java

License:Mozilla Public License

protected IType chooseInterface() {
    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
    if (root == null) {
        return null;
    }// w  ww.ja  va  2  s .c om

    IJavaProject jproject = root.getJavaProject();
    IJavaElement[] elements = new IJavaElement[] { jproject };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);

    try {
        SelectionDialog dialog = JavaUI.createTypeDialog(getShell(), getRunnableContext(), scope,
                IJavaElementSearchConstants.CONSIDER_INTERFACES, false);
        dialog.setTitle(UIPlugin.getString(name + ".InterfaceChooser.title"));
        dialog.setMessage(UIPlugin.getString(name + ".InterfaceChooser.message"));

        if (dialog.open() == dialog.OK) {
            return (IType) dialog.getResult()[0]; //FirstResult();
        }
    } catch (JavaModelException jmex) {
        UIPlugin.log(jmex);
    }
    return null;
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.PackageDialogField.java

License:Mozilla Public License

public IStatus packageChanged() {
    SpindleStatus status = new SpindleStatus();
    checkButtonEnabled();/*from ww w .  ja va 2 s . com*/
    String packName = getTextValue();
    if (!"".equals(packName)) {
        IStatus val = JavaConventions.validatePackageName(packName);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(UIPlugin.getString(name + ".error.InvalidPackageName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(UIPlugin.getString(name + ".warning.DiscouragedPackageName", val.getMessage()));
            // continue
        }
    } else {

        status.setError(UIPlugin.getString(name + ".error.defaultPackage"));
        return status;
    }

    IPackageFragmentRoot root;
    if (container == null) {
        root = null;
    } else {
        root = container.getPackageFragmentRoot();
    }
    if (root != null) {
        IPackageFragment pack = root.getPackageFragment(packName);
        try {
            if (fSourcePackagesOnly && root.getKind() == IPackageFragmentRoot.K_BINARY) {
                status.setError(UIPlugin.getString(name + ".error.PackageMustBeSource"));
                return status;
            }

            IPath rootPath = root.getPath();
            IPath outputPath = root.getJavaProject().getOutputLocation();
            if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                // if the bin folder is inside of our root, dont allow to name a
                // package
                // like the bin folder
                IPath packagePath = pack.getUnderlyingResource().getFullPath();
                if (outputPath.isPrefixOf(packagePath)) {
                    status.setError(UIPlugin.getString(name + ".error.ClashOutputLocation"));
                    return status;
                }
            }
        } catch (JavaModelException e) {
            UIPlugin.log(e);
            // let pass
        }

        currentPackage = pack;
        if (currentPackage != null && nameField != null) {
            try {
                IContainer folder = (IContainer) getPackageFragment().getUnderlyingResource();

                boolean isComponent = nameField.getKind() == AbstractNameField.COMPONENT_NAME;
                IFile file = folder
                        .getFile(new Path(nameField.getTextValue() + (isComponent ? ".jwc" : ".page")));
                if (file.exists()) {

                    status.setError(UIPlugin.getString(name + ".error.ComponentAlreadyExists",
                            file.getFullPath().toString()));
                    return status;
                }
            } catch (JavaModelException e) {
                UIPlugin.log(e);
            }
        }
    } else {
        status.setError("");
    }
    return status;
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.SpecClassDialogField.java

License:Mozilla Public License

protected IStatus typeChanged() {
    SpindleStatus status = new SpindleStatus();

    String specClassname = getTextValue();
    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
    chosenType = null;//from w  w w . j  ava  2  s. co m
    enableButton(root != null);
    if (root == null || "".equals(specClassname.trim())) {
        status.setError(UIPlugin.getString(name + ".error.EnterTypeName"));
        return status;
    }
    try {
        IType specType = resolveTypeName(root.getJavaProject(), specClassname);
        if (specType == null) {
            status.setError(UIPlugin.getString(name + ".warning.TypeNotExists", specClassname));
            return status;
        }
        if (specType.isInterface()) {
            status.setError(UIPlugin.getString(name + ".error.ClassIsNotClass"));
            return status;
        }
        boolean isBinary = specType.isBinary();
        String specBaseTypeName = UIPlugin.getString("TapestryComponentSpec.specBaseClass");
        String specInterfaceName = UIPlugin.getString("TapestryComponentSpec.specInterface");
        if (specBaseTypeName == null || specInterfaceName == null) {
            throw new Error("tapestry component wizard resources missing. Unable to continue");
        }
        IType specBaseType = resolveTypeName(root.getJavaProject(), specBaseTypeName);
        if (specBaseType == null || !specBaseType.exists()) {
            status.setError(UIPlugin.getString(name + ".warning.BaseTypeNotExists", specBaseTypeName));
            return status;
        }

        if (!CoreUtils.extendsType(specType, specBaseType)) {
            if (!CoreUtils.implementsInterface(specType, specInterfaceName)) {
                status.setError(UIPlugin.getString(name + ".error.DoesNotExtendOrImplement"));
                return status;
            }
        }
        chosenType = specType;
    } catch (JavaModelException e) {
        status.setError(name + ".error.couldn't.do.it");
    }
    return status;
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.SuperClassDialogField.java

License:Mozilla Public License

protected IStatus typeChanged() {
    SpindleStatus status = new SpindleStatus();
    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
    //    enableButton(root != null);
    if (root == null) {
        return status;
    }/*from   www.j  av  a  2 s  .  c o  m*/
    String typeName = getTextValue();
    chosenType = null;
    try {
        IType type = resolveTypeName(root.getJavaProject(), typeName);
        if (type == null) {
            status.setWarning(UIPlugin.getString(name + ".warning.TypeNotExists", typeName));
            return status;
        }
        if (type.isInterface()) {
            status.setWarning(UIPlugin.getString(name + ".warning.TypeIsNotClass", typeName));
            return status;
        }

        int flags = type.getFlags();
        if (Flags.isFinal(flags)) {
            status.setWarning(UIPlugin.getString(name + ".warning.TypeIsFinal", typeName));
            return status;
        } else if (!CoreUtils.isVisible(type, packageChooser.getPackageFragment())) {
            status.setWarning(UIPlugin.getString(name + ".warning.TypeIsNotVisible", typeName));
            return status;
        }
        chosenType = type;
    } catch (JavaModelException e) {
        status.setError(UIPlugin.getString(name + ".error.InvalidTypeName"));
        UIPlugin.log(e);
    }
    return status;
}