Search in sources :

Example 1 with CPDCheckDialog

use of net.sourceforge.pmd.eclipse.ui.dialogs.CPDCheckDialog in project pmd-eclipse-plugin by pmd.

the class CPDCheckProjectAction method run.

/*
     * @see org.eclipse.ui.IActionDelegate#run(IAction)
     */
public void run(final IAction action) {
    // NOPMD:UnusedFormalParameter
    final IWorkbenchPartSite site = targetPartSite();
    final ISelection sel = site.getSelectionProvider().getSelection();
    final Shell shell = site.getShell();
    final String[] languages = LanguageFactory.supportedLanguages;
    final String[] formats = { SIMPLE_KEY, XML_KEY, CSV_KEY };
    final CPDCheckDialog dialog = new CPDCheckDialog(shell, languages, formats);
    if (dialog.open() == Dialog.OK && sel instanceof IStructuredSelection) {
        final StructuredSelection ss = (StructuredSelection) sel;
        final Iterator<?> i = ss.iterator();
        while (i.hasNext()) {
            final Object obj = i.next();
            if (obj instanceof IAdaptable) {
                final IAdaptable adaptable = (IAdaptable) obj;
                final IProject project = (IProject) adaptable.getAdapter(IProject.class);
                if (project == null) {
                    LOG.warn("The selected object cannot adapt to a project");
                    LOG.debug("   -> selected object : " + obj);
                } else {
                    this.detectCutAndPaste(project, dialog);
                }
            } else {
                LOG.warn("The selected object is not adaptable");
                LOG.debug("   -> selected object : " + obj);
            }
        }
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IAdaptable(org.eclipse.core.runtime.IAdaptable) Shell(org.eclipse.swt.widgets.Shell) CPDCheckDialog(net.sourceforge.pmd.eclipse.ui.dialogs.CPDCheckDialog) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Aggregations

CPDCheckDialog (net.sourceforge.pmd.eclipse.ui.dialogs.CPDCheckDialog)1 IProject (org.eclipse.core.resources.IProject)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbenchPartSite (org.eclipse.ui.IWorkbenchPartSite)1