Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ae7112c1ef81306d7e627d0ac93e5af4ea762ed9 (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
/*
 * Copyright (c) 2004 - 2012 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.examples.client.offline;

import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.event.IEvent;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.wb.swt.SWTResourceManager;

/**
 * @author Eike Stepper
 */
public abstract class AbstractView<T extends IContainer<?>> extends ViewPart
{
  private final Class<T> objectType;

  private T object;

  private Text events;

  public AbstractView(Class<T> objectType)
  {
    this.objectType = objectType;
    object = Application.NODE.getObject(objectType);
  }

  public Class<T> getObjectType()
  {
    return objectType;
  }

  public T getObject()
  {
    return object;
  }

  @Override
  public void createPartControl(Composite parent)
  {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FillLayout(SWT.HORIZONTAL));

    SashForm sash = new SashForm(container, SWT.SMOOTH | SWT.VERTICAL);

    createPane(sash, object);

    events = new Text(sash, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    events.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));

    sash.setWeights(new int[] { 1, 1 });

    createActions();
    initializeToolBar(getViewSite().getActionBars().getToolBarManager());
    initializeMenu(getViewSite().getActionBars().getMenuManager());
  }

  protected void addEvent(final IEvent event)
  {
    getSite().getShell().getDisplay().asyncExec(new Runnable()
    {
      public void run()
      {
        String text = events.getText();
        // if (text.length() != 0)
        // {
        // text += StringUtil.NL;
        // }
        //
        events.setText(event + StringUtil.NL + text);
      }
    });
  }

  protected void createActions()
  {
    // Create the actions
  }

  protected void initializeToolBar(IToolBarManager toolbarManager)
  {
  }

  protected void initializeMenu(IMenuManager menuManager)
  {
  }

  protected abstract void createPane(Composite parent, T object);
}

Back to the top