Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 603b7467e429d9cbe038b3fa6c0dfea36f2d6810 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (c) 2004-2018 Eike Stepper (Loehne, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.evolution.presentation.quickfix;

import org.eclipse.emf.cdo.evolution.presentation.EvolutionEditor;
import org.eclipse.emf.cdo.evolution.presentation.quickfix.DiagnosticResolution.Generator.Context;

import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.factory.ProductCreationException;

import org.eclipse.emf.common.util.Diagnostic;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.graphics.Image;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Eike Stepper
 */
public abstract class DiagnosticResolution
{
  public static final Diagnostic[] NO_DIAGNOSTICS = {};

  public abstract Image getImage();

  public abstract String getText();

  public abstract String getDescription();

  public abstract void run(Diagnostic diagnostic);

  public void run(Diagnostic[] diagnostics, IProgressMonitor monitor)
  {
    for (Diagnostic diagnostic : diagnostics)
    {
      monitor.subTask(diagnostic.getMessage());
      run(diagnostic);
    }
  }

  public Diagnostic[] findOtherDiagnostics(Diagnostic[] diagnostics)
  {
    return NO_DIAGNOSTICS;
  }

  public static DiagnosticResolution[] getResolutions(Diagnostic diagnostic, final EvolutionEditor editor)
  {
    final List<DiagnosticResolution> result = new ArrayList<DiagnosticResolution>();
    Context context = new Generator.Context()
    {
      public EvolutionEditor getEditor()
      {
        return editor;
      }

      public void add(DiagnosticResolution resolution)
      {
        result.add(resolution);
      }
    };

    for (String factoryType : IPluginContainer.INSTANCE.getFactoryTypes(Generator.Factory.PRODUCT_GROUP))
    {
      Generator generator = (Generator)IPluginContainer.INSTANCE.getElement(Generator.Factory.PRODUCT_GROUP, factoryType, null);
      generator.getResolutions(diagnostic, context);
    }

    return result.toArray(new DiagnosticResolution[result.size()]);
  }

  /**
   * @author Eike Stepper
   */
  public interface Generator
  {
    public void getResolutions(Diagnostic diagnostic, Context context);

    /**
     * @author Eike Stepper
     */
    public interface Context
    {
      public EvolutionEditor getEditor();

      public void add(DiagnosticResolution resolution);
    }

    /**
     * @author Eike Stepper
     */
    public static abstract class Factory extends org.eclipse.net4j.util.factory.Factory
    {
      public static final String PRODUCT_GROUP = "org.eclipse.emf.cdo.evolution.diagnosticResolutionGenerators";

      public static final String DEFAULT_TYPE = "default";

      public Factory()
      {
        this(DEFAULT_TYPE);
      }

      public Factory(String type)
      {
        super(PRODUCT_GROUP, type);
      }

      public abstract Generator create(String description) throws ProductCreationException;
    }
  }
}

Back to the top