Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1c4de4258cbf0874ee2d06a7b194575740f8fdfb (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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
 * 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.internal.ui.dialogs;

import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.ui.widgets.ComposeBranchPointComposite;

import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.ui.UIUtil;
import org.eclipse.net4j.util.ui.ValidationContext;

import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPage;

/**
 * @author Eike Stepper
 */
public class SelectBranchPointDialog extends TitleAreaDialog implements ValidationContext
{
  protected final ValidationContext aggregator = new ValidationContext.Aggregator(this);

  private CDOSession session;

  private CDOBranchPoint branchPoint;

  private boolean allowTimeStamp;

  private CTabItem composeTab;

  private CTabItem commitsTab;

  private CTabItem tagsTab;

  private CTabItem viewsTab;

  public SelectBranchPointDialog(IWorkbenchPage page, CDOSession session, CDOBranchPoint branchPoint,
      boolean allowTimeStamp)
  {
    super(page.getWorkbenchWindow().getShell());
    setShellStyle(getShellStyle() | SWT.APPLICATION_MODAL | SWT.MAX | SWT.TITLE | SWT.RESIZE);

    this.session = session;
    this.branchPoint = branchPoint;
    this.allowTimeStamp = allowTimeStamp;
  }

  public CDOSession getSession()
  {
    return session;
  }

  public boolean isAllowTimeStamp()
  {
    return allowTimeStamp;
  }

  public CTabItem getComposeTab()
  {
    return composeTab;
  }

  public CTabItem getCommitsTab()
  {
    return commitsTab;
  }

  public CTabItem getTagsTab()
  {
    return tagsTab;
  }

  public CTabItem getViewsTab()
  {
    return viewsTab;
  }

  public CDOBranchPoint getBranchPoint()
  {
    return branchPoint;
  }

  public void setBranchPoint(CDOBranchPoint branchPoint)
  {
    this.branchPoint = branchPoint;
    validate();
  }

  public void setValidationError(Object source, String message)
  {
    setMessage(message, IMessageProvider.ERROR);
  }

  @Override
  protected void configureShell(Shell newShell)
  {
    super.configureShell(newShell);
    newShell.setSize(500, 500);
  }

  @Override
  protected Control createDialogArea(Composite parent)
  {
    Composite composite = (Composite)super.createDialogArea(parent);
    composite.setLayoutData(UIUtil.createGridData());
    composite.setLayout(new GridLayout(1, false));

    createBranchPointArea(composite);
    UIUtil.setValidationContext(composite, aggregator);

    return composite;
  }

  protected void createBranchPointArea(Composite parent)
  {
    CTabFolder tabFolder = new CTabFolder(parent, SWT.BORDER);
    tabFolder.setSimple(false);
    tabFolder.setLayoutData(UIUtil.createGridData());
    tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));

    composeTab = new CTabItem(tabFolder, SWT.NONE);
    composeTab.setText(getComposeTabTitle());
    Composite composite_0 = new Composite(tabFolder, SWT.NONE);
    composite_0.setLayout(new GridLayout(1, false));
    createComposeTab(composite_0);
    composeTab.setControl(composite_0);

    commitsTab = new CTabItem(tabFolder, SWT.NONE);
    commitsTab.setText("Commits");
    Composite composite_1 = new Composite(tabFolder, SWT.NONE);
    composite_1.setLayout(new GridLayout(1, false));
    createCommitsTab(composite_1);
    commitsTab.setControl(composite_1);

    tagsTab = new CTabItem(tabFolder, SWT.NONE);
    tagsTab.setText("Tags");
    Composite composite_2 = new Composite(tabFolder, SWT.NONE);
    composite_2.setLayout(new GridLayout(1, false));
    createTagsTab(composite_2);
    tagsTab.setControl(composite_2);

    viewsTab = new CTabItem(tabFolder, SWT.NONE);
    viewsTab.setText("Views");
    Composite composite_3 = new Composite(tabFolder, SWT.NONE);
    composite_3.setLayout(new GridLayout(1, false));
    createViewsTab(composite_3);
    viewsTab.setControl(composite_3);

    tabFolder.setSelection(composeTab);
  }

  protected void createComposeTab(Composite parent)
  {
    Control control = new ComposeBranchPointComposite(parent, SWT.NONE, session, null, allowTimeStamp)
    {
      @Override
      protected void branchPointChanged(CDOBranchPoint newBranchPoint)
      {
        setBranchPoint(newBranchPoint);
      }
    };

    control.setLayoutData(UIUtil.createGridData());
  }

  protected void createCommitsTab(Composite parent)
  {
  }

  protected void createTagsTab(Composite parent)
  {
  }

  protected void createViewsTab(Composite parent)
  {
  }

  protected String getComposeTabTitle()
  {
    return "Compose";
  }

  protected void validate()
  {
  }

  /**
   * @author Eike Stepper
   */
  public static class WithName extends SelectBranchPointDialog
  {
    private String name;

    private Text nameText;

    public WithName(IWorkbenchPage page, CDOSession session, CDOBranchPoint branchPoint, boolean allowTimeStamp,
        String name)
    {
      super(page, session, branchPoint, allowTimeStamp);
      this.name = StringUtil.safe(name);
    }

    public String getName()
    {
      return name;
    }

    public void setName(String name)
    {
      this.name = name;
      validate();
    }

    public Text getNameText()
    {
      return nameText;
    }

    @Override
    protected void createBranchPointArea(Composite parent)
    {
      GridLayout gridLayout = UIUtil.createGridLayout(2);
      gridLayout.marginHeight = 5;
      gridLayout.horizontalSpacing = 5;

      Composite composite = new Composite(parent, SWT.NONE);
      composite.setLayoutData(UIUtil.createGridData(true, false));
      composite.setLayout(gridLayout);

      Label label = new Label(composite, SWT.NONE);
      label.setLayoutData(UIUtil.createGridData(false, false));
      label.setText("Name:");

      nameText = new Text(composite, SWT.BORDER);
      nameText.setLayoutData(UIUtil.createGridData(true, false));
      nameText.setText(name);
      nameText.addModifyListener(new ModifyListener()
      {
        public void modifyText(ModifyEvent e)
        {
          setName(nameText.getText());
        }
      });

      super.createBranchPointArea(parent);
    }
  }
}

Back to the top