Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c9a09180e7df103d290ad2b9d7c66d2ee83629a7 (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
/***************************************************************************
 * 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.preferences;

import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;

import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.ui.prefs.OMPreferencePage;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
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.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

/**
 * @author Eike Stepper
 */
public class CDOPreferencePage extends OMPreferencePage
{
  private Text repositoryName;

  private Text userName;

  private Text connectorDescription;

  private TextAndDisable referenceChunkSize;

  private TextAndDisable preloadChunkSize;

  private Button invalidationNotifications;

  private SelectionListener selectionListener = new SelectionListener()
  {
    public void widgetDefaultSelected(SelectionEvent e)
    {
      dialogChanged();
    }

    public void widgetSelected(SelectionEvent e)
    {
      dialogChanged();
    }
  };

  private ModifyListener modifyListener = new ModifyListener()
  {
    public void modifyText(ModifyEvent e)
    {
      dialogChanged();
    }
  };

  public CDOPreferencePage()
  {
    super(org.eclipse.emf.internal.cdo.bundle.OM.PREFS);
    // setDescription("CDO Preferences");
  }

  @Override
  protected Control createContents(Composite parent)
  {
    GridLayout grid = new GridLayout(1, false);
    grid.marginHeight = 0;
    grid.marginWidth = 0;

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(grid);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Group sessionGroup = new Group(composite, SWT.NONE);
    sessionGroup.setText("Session Defaults");
    sessionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    sessionGroup.setLayout(new GridLayout(2, false));

    new Label(sessionGroup, SWT.NONE).setText("Repository name:");
    repositoryName = new Text(sessionGroup, SWT.BORDER);
    repositoryName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    repositoryName.addModifyListener(modifyListener);

    new Label(sessionGroup, SWT.NONE).setText("User name:");
    userName = new Text(sessionGroup, SWT.BORDER);
    userName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    userName.addModifyListener(modifyListener);

    new Label(sessionGroup, SWT.NONE).setText("Connector description:");
    connectorDescription = new Text(sessionGroup, SWT.BORDER);
    connectorDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    connectorDescription.addModifyListener(modifyListener);

    new Label(sessionGroup, SWT.NONE).setText("Reference chunk size:");
    referenceChunkSize = new TextAndDisable(sessionGroup, SWT.BORDER, String.valueOf(CDORevision.UNCHUNKED));
    referenceChunkSize.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    referenceChunkSize.getText().addModifyListener(modifyListener);
    referenceChunkSize.getButton().addSelectionListener(selectionListener);

    Group viewGroup = new Group(composite, SWT.NONE);
    viewGroup.setText("View Defaults");
    viewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    viewGroup.setLayout(new GridLayout(2, false));

    new Label(viewGroup, SWT.NONE).setText("Preload chunk size:");
    preloadChunkSize = new TextAndDisable(viewGroup, SWT.BORDER, String.valueOf(CDOView.NO_PRELOAD));
    preloadChunkSize.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    preloadChunkSize.getText().addModifyListener(modifyListener);
    preloadChunkSize.getButton().addSelectionListener(selectionListener);

    new Label(viewGroup, SWT.NONE).setText("EMF invalidation notifications:");
    invalidationNotifications = new Button(viewGroup, SWT.CHECK);
    invalidationNotifications.addSelectionListener(selectionListener);

    initValues();
    return composite;
  }

  protected void initValues()
  {
    repositoryName.setText(org.eclipse.emf.internal.cdo.bundle.OM.PREF_REPOSITORY_NAME.getValue());
    userName.setText(org.eclipse.emf.internal.cdo.bundle.OM.PREF_USER_NAME.getValue());
    connectorDescription.setText(org.eclipse.emf.internal.cdo.bundle.OM.PREF_CONNECTOR_DESCRIPTION.getValue());
    referenceChunkSize.setValue(String.valueOf(org.eclipse.emf.internal.cdo.bundle.OM.PREF_REFERENCE_CHUNK_SIZE
        .getValue()));
    preloadChunkSize.setValue(String
        .valueOf(org.eclipse.emf.internal.cdo.bundle.OM.PREF_LOAD_REVISION_COLLECTION_CHUNK_SIZE.getValue()));
    invalidationNotifications
        .setSelection(org.eclipse.emf.internal.cdo.bundle.OM.PREF_ENABLE_INVALIDATION_NOTIFICATIONS.getValue());
  }

  @Override
  public boolean performOk()
  {
    org.eclipse.emf.internal.cdo.bundle.OM.PREF_REPOSITORY_NAME.setValue(repositoryName.getText());
    org.eclipse.emf.internal.cdo.bundle.OM.PREF_USER_NAME.setValue(userName.getText());
    org.eclipse.emf.internal.cdo.bundle.OM.PREF_CONNECTOR_DESCRIPTION.setValue(connectorDescription.getText());

    int v1 = Integer.parseInt(referenceChunkSize.getText().getText());
    org.eclipse.emf.internal.cdo.bundle.OM.PREF_REFERENCE_CHUNK_SIZE.setValue(v1);

    int v2 = Integer.parseInt(preloadChunkSize.getText().getText());
    org.eclipse.emf.internal.cdo.bundle.OM.PREF_LOAD_REVISION_COLLECTION_CHUNK_SIZE.setValue(v2);

    boolean v3 = invalidationNotifications.getSelection();
    org.eclipse.emf.internal.cdo.bundle.OM.PREF_ENABLE_INVALIDATION_NOTIFICATIONS.setValue(v3);

    return super.performOk();
  }

  protected void dialogChanged()
  {
  }

  private static final class TextAndDisable extends Composite implements SelectionListener, ModifyListener
  {
    private Text text;

    private Button disabled;

    private String disabledValue;

    public TextAndDisable(Composite parent, int textStyle, String disabledValue)
    {
      super(parent, SWT.NONE);
      this.disabledValue = disabledValue;

      GridLayout grid = new GridLayout(2, false);
      grid.marginHeight = 0;
      grid.marginWidth = 0;
      setLayout(grid);

      GridData gd = new GridData();
      gd.widthHint = 32;

      text = new Text(this, textStyle);
      text.addModifyListener(this);
      text.setLayoutData(gd);

      disabled = new Button(this, SWT.CHECK);
      disabled.setText("Disabled");
      disabled.addSelectionListener(this);
      disabled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    }

    public Text getText()
    {
      return text;
    }

    public Button getButton()
    {
      return disabled;
    }

    public boolean isDisabled()
    {
      return disabled.getSelection();
    }

    public void setDisabled(boolean disabled)
    {
      this.disabled.setSelection(disabled);
      widgetSelected(null);
    }

    public void setValue(String value)
    {
      text.setText(value);
      setDisabled(ObjectUtil.equals(value, disabledValue));
    }

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

    public void widgetSelected(SelectionEvent e)
    {
      if (isDisabled())
      {
        text.setText(disabledValue);
        text.setEnabled(false);
      }
      else
      {
        text.setEnabled(true);
      }
    }

    public void modifyText(ModifyEvent e)
    {
    }
  }
}

Back to the top