Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a8594f19392ddbd7e283a482b2d543ed20df6951 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
 * Copyright (c) 2004 - 2011 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:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.ui.efs.wizards;

import org.eclipse.net4j.util.ui.UIUtil;
import org.eclipse.net4j.util.ui.container.ElementWizardComposite;
import org.eclipse.net4j.util.ui.container.IElementWizard.ValidationContext;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;

import java.net.URI;

/**
 * @author Martin Fluegge
 */
public class CDOProjectImportWizard extends Wizard implements IImportWizard
{
  public CDOProjectImportWizard()
  {
  }

  public void init(IWorkbench workbench, IStructuredSelection selection)
  {
  }

  @Override
  public boolean performFinish()
  {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();

    String projectName = "cdo_test1";
    IProject project = workspace.getRoot().getProject(projectName);
    if (project.exists())
    {
      return false;
    }

    IProjectDescription description = workspace.newProjectDescription(projectName);
    description.setLocationURI(URI.create("cdo.net4j.tcp://localhost/repo1/MAIN/@"));

    try
    {
      project.create(description, new NullProgressMonitor());
      if (!project.isOpen())
      {
        project.open(new NullProgressMonitor());
      }
    }
    catch (CoreException ex)
    {
      ex.printStackTrace();
      return false;
    }

    return true;
  }

  @Override
  public void addPages()
  {
    addPage(new Page());
  }

  /**
   * @author Eike Stepper
   */
  public static class Page extends WizardPage implements ValidationContext
  {
    public Page()
    {
      super("CDOProjectImportWizardPage");
    }

    public void createControl(Composite parent)
    {
      Composite composite = new Composite(parent, SWT.FILL);
      // FillLayout layout = new FillLayout(SWT.VERTICAL);
      GridLayout layout = new GridLayout(1, true);

      composite.setLayout(layout);
      // composite.setLayout(new GridLayout(1, true));

      Group repositoryGroup = new Group(composite, SWT.NONE);
      repositoryGroup.setLayout(new GridLayout(2, false));
      repositoryGroup.setLayoutData(UIUtil.createGridData(true, false));

      createRepositoryControl(repositoryGroup);

      Group group = new Group(composite, SWT.NONE);
      group.setText("Connection");
      group.setLayout(new FillLayout());
      group.setLayoutData(UIUtil.createGridData(true, true));

      new ElementWizardComposite.WithRadios(group, SWT.NONE, "org.eclipse.net4j.connectors", "Type:");
      setControl(group);
    }

    private void createRepositoryControl(Composite parent)
    {
      Label repositoryLabel = new Label(parent, SWT.NONE);
      repositoryLabel.setText("Repository:");
      repositoryLabel.setLayoutData(UIUtil.createGridData(false, false));

      Text repositoryText = new Text(parent, SWT.BORDER);
      repositoryText.setLayoutData(UIUtil.createGridData(true, false));
    }

    public void setValidationOK()
    {
      setMessage(null);
    }

    public void setValidationError(Control control, String message)
    {
      setMessage(message, IMessageProvider.ERROR);
    }
  }
}

Back to the top