Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c2cb186175fd47822e41b37c89c2b6dd750b906d (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
/***************************************************************************
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
 * 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.internal.ui.actions;

import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.internal.ui.bundle.OM;

import org.eclipse.net4j.internal.util.collection.PreferenceHistory;
import org.eclipse.net4j.ui.widgets.HistoryTextDialog;
import org.eclipse.net4j.util.collection.IHistory;

import org.eclipse.emf.ecore.EPackage;

import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;

/**
 * @author Eike Stepper
 */
public class RegisterCDOPackageAction extends RegisterPackageAction
{
  public static final IHistory<String> HISTORY = new PreferenceHistory(OM.PREF_HISTORY_REGISTER_PACKAGE);

  private static final String TITLE = "Register Package";

  private EPackage.Registry registry = EPackage.Registry.INSTANCE;

  public RegisterCDOPackageAction(IWorkbenchPage page, CDOSession session)
  {
    super(page, TITLE, "Register a package generated for CDO", null, session);
  }

  @Override
  protected EPackage getEPackage(IWorkbenchPage page, CDOSession session)
  {
    Shell shell = page.getWorkbenchWindow().getShell();
    IInputValidator validator = new EPackageFactoryValidator();
    InputDialog dialog = new HistoryTextDialog(shell, TITLE, "Enter a package URI:", HISTORY, validator);
    if (dialog.open() == InputDialog.OK)
    {
      String uri = dialog.getValue();
      HISTORY.add(uri);
      return registry.getEPackage(uri);
    }

    return null;
  }

  /**
   * @author Eike Stepper
   */
  public class EPackageFactoryValidator implements IInputValidator
  {
    public String isValid(String uri)
    {
      if (uri == null || uri.length() == 0)
      {
        return "";
      }

      return registry.containsKey(uri) ? null : "Package " + uri + " not found.";
    }
  }
}

Back to the top