Search in sources :

Example 16 with CheckCatalog

use of com.avaloq.tools.ddk.check.check.CheckCatalog in project dsl-devkit by dsldevkit.

the class CheckExtensionGenerator method removeExtensions.

/**
 * Removes extensions registered for a check catalog. This operation has extension point specific behavior.
 * Validator, quickfix and preference extensions can safely be removed without any checking. The marker help
 * extension, however, contains elements from all catalogs of current project. Therefore only elements belonging
 * to given catalog may be removed, and not the whole extension. Table of contents and contexts extensions are
 * never removed once created - they are not catalog specific and do not harm.
 *
 * @param file
 *          the plugin.xml file to be modified
 * @param object
 *          the object
 * @param monitor
 *          a progress monitor
 * @throws CoreException
 *           if the file is read-only and cannot be edited
 */
private void removeExtensions(final IFile file, final Object object, final IProgressMonitor monitor) throws CoreException {
    // null means don't contact me...
    IStatus status = PDEPlugin.getWorkspace().validateEdit(new IFile[] { file }, null);
    if (status.getSeverity() != IStatus.OK) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), IStatus.ERROR, "Could not remove plugin extensions", null));
    }
    if (!STANDARD_PLUGIN_FILENAME.equals(file.getName())) {
        WorkspacePluginModel pluginModel = new CheckWorkspacePluginModel(file, false);
        IPluginBase base = pluginModel.getPluginBase();
        base.setSchemaVersion(TargetPlatformHelper.getSchemaVersion());
        pluginModel.load();
        if (object instanceof IEObjectDescription) {
            // called when catalog is deleted
            manager.removeExtensions((IEObjectDescription) object, pluginModel, monitor);
        } else if (object instanceof CheckCatalog) {
            // called in order to remove extensions in an invalid model
            manager.removeExtensions((CheckCatalog) object, pluginModel, monitor);
        }
        pluginModel.save();
    } else {
        final ModelModification mod = new ModelModification(file) {

            @Override
            protected void modifyModel(final IBaseModel model, final IProgressMonitor monitor) throws CoreException {
                if (!(model instanceof IPluginModelBase)) {
                    return;
                }
                IPluginModelBase pluginModel = (IPluginModelBase) model;
                if (object instanceof IEObjectDescription) {
                    // called when catalog is deleted
                    manager.removeExtensions((IEObjectDescription) object, pluginModel, monitor);
                } else if (object instanceof CheckCatalog) {
                    // called in order to remove extensions in an invalid model
                    manager.removeExtensions((CheckCatalog) object, pluginModel, monitor);
                }
            }

            @Override
            public boolean saveOpenEditor() {
                // prevent modifications to open plugin manifest editor; the editor will become dirty once the modification is performed
                return false;
            }
        };
        modifyModel(mod, monitor);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IBaseModel(org.eclipse.pde.core.IBaseModel) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPluginBase(org.eclipse.pde.core.plugin.IPluginBase) CoreException(org.eclipse.core.runtime.CoreException) ModelModification(org.eclipse.pde.internal.ui.util.ModelModification) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) IPluginModelBase(org.eclipse.pde.core.plugin.IPluginModelBase) WorkspacePluginModel(org.eclipse.pde.internal.core.plugin.WorkspacePluginModel) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 17 with CheckCatalog

use of com.avaloq.tools.ddk.check.check.CheckCatalog in project dsl-devkit by dsldevkit.

the class CheckHoverProvider method getHoverInfoAsHtml.

@Override
protected String getHoverInfoAsHtml(final EObject object) {
    if (!hasHover(object) || object.eIsProxy()) {
        // TODO object will be proxy in CA when referencing CheckCatalogs!
        return null;
    }
    if (object instanceof Check) {
        Check check = (Check) object;
        // a dispatcher would be nice
        StringBuffer buffer = new StringBuffer();
        buffer.append(getFirstLine(check));
        appendSection(buffer, "Description", generatorExtension.formatDescription(check.getDescription()));
        appendSection(buffer, "Message", generatorExtension.replacePlaceholder(check.getMessage()));
        return buffer.toString();
    } else if (object instanceof CheckCatalog) {
        CheckCatalog catalog = (CheckCatalog) object;
        StringBuffer buffer = new StringBuffer();
        buffer.append(getFirstLine(catalog));
        appendSection(buffer, "Description", generatorExtension.formatDescription(catalog.getDescription()));
        return buffer.toString();
    }
    return super.getHoverInfoAsHtml(object);
}
Also used : Check(com.avaloq.tools.ddk.check.check.Check) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog)

Aggregations

CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)17 IPluginElement (org.eclipse.pde.core.plugin.IPluginElement)4 IPluginExtension (org.eclipse.pde.core.plugin.IPluginExtension)4 Test (org.junit.Test)4 Check (com.avaloq.tools.ddk.check.check.Check)3 ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)3 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)3 FormalParameter (com.avaloq.tools.ddk.check.check.FormalParameter)2 CheckConfiguration (com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration)2 Function (com.google.common.base.Function)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 Template (org.eclipse.jface.text.templates.Template)2 TemplateProposal (org.eclipse.jface.text.templates.TemplateProposal)2 IPluginObject (org.eclipse.pde.core.plugin.IPluginObject)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 Check (org.eclipse.xtext.validation.Check)2 Category (com.avaloq.tools.ddk.check.check.Category)1