Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8f0ed500d8a1032d5261199104d22589a181b83a (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
/*
 * Copyright (c) 2012, 2019 Eike Stepper (Loehne, 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.examples.client.offline;

import org.eclipse.emf.cdo.examples.client.offline.nodes.NodeType;
import org.eclipse.emf.cdo.server.IRepository;

import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Label;
import org.eclipse.swt.widgets.Text;

/**
 * @author Eike Stepper
 */
public class RepositoryDetails extends Composite
{
  private IRepository repository;

  private Text node;

  private Text name;

  private Text type;

  private Text state;

  private Button connected;

  public RepositoryDetails(Composite parent, IRepository repository, final Control enablementControl)
  {
    super(parent, SWT.NONE);
    this.repository = repository;

    setLayout(new GridLayout(2, false));

    Label lblNodeName = new Label(this, SWT.NONE);
    lblNodeName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblNodeName.setText("Node:");

    node = new Text(this, SWT.BORDER);
    node.setEditable(false);
    node.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    node.setText(Application.NODE.getName());

    Label lblName = new Label(this, SWT.NONE);
    lblName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblName.setText("Name:");

    name = new Text(this, SWT.BORDER);
    name.setEditable(false);
    name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    name.setText(repository.getName());

    Label lblType = new Label(this, SWT.NONE);
    lblType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblType.setText("Type:");

    type = new Text(this, SWT.BORDER);
    type.setEditable(false);
    type.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblState = new Label(this, SWT.NONE);
    lblState.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblState.setText("State:");

    state = new Text(this, SWT.BORDER);
    state.setEditable(false);
    state.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    NodeType nodeType = Application.NODE.getType();
    if (nodeType instanceof NodeType.Server && !(nodeType instanceof NodeType.FailoverMonitor))
    {
      final NodeType.Server server = (NodeType.Server)nodeType;

      new Label(this, SWT.NONE);

      connected = new Button(this, SWT.CHECK);
      connected.setText("Connected to Network");
      connected.setSelection(true);
      connected.addSelectionListener(new SelectionAdapter()
      {
        @Override
        public void widgetSelected(SelectionEvent e)
        {
          boolean on = connected.getSelection();
          enablementControl.setEnabled(on);

          server.setConnectedToNetwork(Application.NODE, on);
        }
      });
    }

    updateUI();
    repository.addListener(new IListener()
    {
      @Override
      public void notifyEvent(IEvent event)
      {
        if (!isDisposed())
        {
          getDisplay().asyncExec(new Runnable()
          {
            @Override
            public void run()
            {
              updateUI();
            }
          });
        }
      }
    });
  }

  private void updateUI()
  {
    type.setText(repository.getType().toString());
    state.setText(repository.getState().toString());
  }
}

Back to the top