Skip to main content
summaryrefslogtreecommitdiffstats
blob: a12eda7ab2de6b1c0108c993497791ed2c931a14 (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
/*
 * Copyright (c) 2013 Eike Stepper (Berlin, 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:
 *    Christian W. Damus (CEA LIST) - initial API and implementation
 */
package org.eclipse.emf.cdo.security.internal.ui.editor;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;

import org.eclipse.ui.IActionBars;
import org.eclipse.ui.forms.IDetailsPage;
import org.eclipse.ui.forms.IDetailsPageProvider;

import java.util.Map;

/**
 * A master/details-block details page provider that maps details pages
 * simply by {@link EClass}.
 * 
 * @author Christian W. Damus (CEA LIST)
 * 
 * @see #builder(IActionBars)
 */
public class EClassDetailsPageProvider implements IDetailsPageProvider
{

  private final Map<EClass, IDetailsPage> pages = new java.util.HashMap<EClass, IDetailsPage>();

  private EClassDetailsPageProvider()
  {
  }

  public static Builder builder(IActionBars editorActionBars)
  {
    return new Builder(editorActionBars);
  }

  public Object getPageKey(Object object)
  {
    return object instanceof EObject ? ((EObject)object).eClass() : null;
  }

  public IDetailsPage getPage(Object key)
  {
    return pages.get(key);
  }

  //
  // Nested types
  //

  public static class Builder
  {
    private final Map<EClass, IDetailsPage> pages = new java.util.HashMap<EClass, IDetailsPage>();

    private final IActionBars actionBars;

    private Builder(IActionBars actionBars)
    {
      this.actionBars = actionBars;
    }

    public Builder page(EClass eclass, IDetailsPage page)
    {
      if (page instanceof AbstractSectionPart<?>)
      {
        ((AbstractSectionPart<?>)page).setEditorActionBars(actionBars);
      }

      pages.put(eclass, page);

      return this;
    }

    public EClassDetailsPageProvider build()
    {
      EClassDetailsPageProvider result = new EClassDetailsPageProvider();
      result.pages.putAll(pages);
      return result;
    }
  }
}

Back to the top