Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 523238d4a13630d19076ee057a32da293803ddea (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
 * Copyright (c) 2015, 2016 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.explorer.ui.checkouts.wizards;

import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.cdo.explorer.repositories.CDORepository;
import org.eclipse.emf.cdo.explorer.repositories.CDORepository.IDGeneration;
import org.eclipse.emf.cdo.explorer.repositories.CDORepository.VersioningMode;
import org.eclipse.emf.cdo.explorer.ui.bundle.OM;
import org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutImpl;

import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.ui.UIUtil;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import java.util.Properties;

/**
 * @author Eike Stepper
 */
public class CheckoutTypePage extends CheckoutWizardPage
{
  private CDORepository repository;

  private String type = CDOCheckout.TYPE_ONLINE_TRANSACTIONAL;

  private Button transactionalButton;

  private Button historicalButton;

  private Button offlineButton;

  public CheckoutTypePage()
  {
    super("Checkout Type", "Select the type of the new checkout.");
  }

  public final String getType()
  {
    return type;
  }

  public final void setType(String type)
  {
    if (!ObjectUtil.equals(this.type, type))
    {
      log("Setting type to " + type);
      this.type = type;

      typeChanged(type);
    }
  }

  @Override
  protected GridData createCompositeGridData()
  {
    return new GridData(SWT.CENTER, SWT.CENTER, true, true);
  }

  @Override
  protected void createUI(Composite parent)
  {
    transactionalButton = addChoice(parent, "Online Transactional", "icons/transactional.gif", "Creates a remote connection for online editing.",
        CDOCheckout.TYPE_ONLINE_TRANSACTIONAL);

    historicalButton = addChoice(parent, "Online Historical", "icons/historical.gif", "Creates a remote connection for online auditing.",
        CDOCheckout.TYPE_ONLINE_HISTORICAL);

    offlineButton = addChoice(parent, "Offline", "icons/disconnect.gif", "Creates a local checkout for offline editing.", CDOCheckout.TYPE_OFFLINE);
  }

  private Button addChoice(Composite composite, String text, String imagePath, String description, final String type)
  {
    final SelectionListener listener = new SelectionListener()
    {
      public void widgetSelected(SelectionEvent e)
      {
        CheckoutTypePage.this.setType(type);
        validate();
      }

      public void widgetDefaultSelected(SelectionEvent e)
      {
        widgetSelected(e);
        showNextPage();
      }
    };

    Button button = new Button(composite, SWT.RADIO);
    button.setText(text);
    button.addSelectionListener(listener);
    button.addMouseListener(new MouseAdapter()
    {
      @Override
      public void mouseDoubleClick(MouseEvent e)
      {
        listener.widgetDefaultSelected(null);
      }
    });

    GridLayout descriptionLayout = UIUtil.createGridLayout(2);
    descriptionLayout.marginLeft = 20;
    descriptionLayout.horizontalSpacing = 5;

    Composite descriptionComposite = new Composite(composite, SWT.NONE);
    descriptionComposite.setLayout(descriptionLayout);

    Label imageLabel = new Label(descriptionComposite, SWT.NONE);
    imageLabel.setImage(OM.getImage(imagePath));

    Label descriptionLabel = new Label(descriptionComposite, SWT.NONE);
    descriptionLabel.setText(description);

    new Label(composite, SWT.NONE);
    return button;
  }

  private Button getButton(String type)
  {
    if (type == CDOCheckout.TYPE_ONLINE_TRANSACTIONAL)
    {
      return transactionalButton;
    }

    if (type == CDOCheckout.TYPE_ONLINE_HISTORICAL)
    {
      return historicalButton;
    }

    if (type == CDOCheckout.TYPE_OFFLINE)
    {
      return offlineButton;
    }

    return null;
  }

  @Override
  protected void repositoryChanged(CDORepository repository)
  {
    this.repository = repository;

    Button button = getButton(type);
    if (button != null && !button.isEnabled())
    {
      setType(CDOCheckout.TYPE_ONLINE_TRANSACTIONAL);
    }

    super.repositoryChanged(repository);
  }

  @Override
  protected void pageActivated()
  {
    if (transactionalButton != null)
    {
      transactionalButton.setEnabled(false);
      historicalButton.setEnabled(false);
      offlineButton.setEnabled(false);

      if (repository != null)
      {
        transactionalButton.setEnabled(true);

        VersioningMode versioningMode = repository.getVersioningMode();
        if (versioningMode == null || versioningMode.isSupportingAudits())
        {
          historicalButton.setEnabled(true);
          IDGeneration idGeneration = repository.getIDGeneration();
          if (idGeneration == null || idGeneration == IDGeneration.UUID)
          {
            offlineButton.setEnabled(true);
          }
        }

        if (historicalButton.getSelection() && !historicalButton.isEnabled())
        {
          setType(CDOCheckout.TYPE_ONLINE_TRANSACTIONAL);
        }
        else if (offlineButton.getSelection() && !offlineButton.isEnabled())
        {
          setType(CDOCheckout.TYPE_ONLINE_TRANSACTIONAL);
        }
      }

      transactionalButton.setSelection(CDOCheckout.TYPE_ONLINE_TRANSACTIONAL.equals(type));
    }

    historicalButton.setSelection(CDOCheckout.TYPE_ONLINE_HISTORICAL.equals(type));
    offlineButton.setSelection(CDOCheckout.TYPE_OFFLINE.equals(type));
  }

  @Override
  protected boolean doValidate() throws ValidationProblem
  {
    return true;
  }

  @Override
  protected void fillProperties(Properties properties)
  {
    properties.setProperty(CDOCheckoutImpl.PROP_TYPE, type);
    properties.setProperty(CDOCheckoutImpl.PROP_READ_ONLY, Boolean.toString(CDOCheckout.TYPE_ONLINE_HISTORICAL.equals(type)));
  }
}

Back to the top