Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 99c5ac1d62e08ae4bcd5bbdb4b340537a1bf36e0 (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
/*
 * Copyright (c) 2011, 2012, 2015, 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:
 *     Martin Fluegge - initial API and implementation
 */
package org.eclipse.emf.cdo.dawn.graphiti.wizards;

import org.eclipse.emf.cdo.dawn.graphiti.DawnGraphitiUIPlugin;

import org.eclipse.graphiti.dt.IDiagramType;
import org.eclipse.graphiti.ui.services.GraphitiUi;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.resource.ImageDescriptor;
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.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import java.util.Arrays;
import java.util.List;
import java.util.Vector;

/**
 * @author Martin Fluegge
 */
public class DawnGraphitiyDiagramTypeSelectionWizardPage extends AbstractDawnGraphitiWizardPage
{
  private static final String PAGE_DESC = "description";

  private static final String PAGE_TITLE = "title";

  private static final String DEFAULT_TYPE = "tutorial"; //$NON-NLS-1$

  private static final String SELECTED_TYPE = "selectedtype"; //$NON-NLS-1$

  private Combo comboBox;

  public DawnGraphitiyDiagramTypeSelectionWizardPage(String pageName, String title, ImageDescriptor titleImage)
  {
    super(pageName, title, titleImage);
  }

  protected DawnGraphitiyDiagramTypeSelectionWizardPage(String pageName)
  {
    super(pageName);
    setTitle(PAGE_TITLE);
    setDescription(PAGE_DESC);
  }

  @Override
  protected void createWizardContents(Composite parent)
  {
    // project specification group
    Composite projectGroup = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    projectGroup.setLayout(layout);
    projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // new project label
    Label projectLabel = new Label(projectGroup, SWT.NONE);
    projectLabel.setFont(parent.getFont());
    projectLabel.setText("set text");

    // new project name entry field
    comboBox = new Combo(projectGroup, SWT.READ_ONLY | SWT.BORDER);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 250;
    comboBox.setLayoutData(data);
    comboBox.setFont(parent.getFont());
    comboBox.setVisibleItemCount(12);
    comboBox.addSelectionListener(new SelectionAdapter()
    {

      @Override
      public void widgetSelected(SelectionEvent e)
      {
        IDialogSettings dialogSettings = DawnGraphitiUIPlugin.getDefault().getDialogSettings();
        dialogSettings.put(SELECTED_TYPE, comboBox.getText());
      }
    });

    // set the contents of the Combo-widget
    comboBox.setItems(getAllAvailableDiagramTypes());
    if (getInitialValue() != null)
    {
      comboBox.setText(getInitialValue());
    }
  }

  protected String[] getAllAvailableDiagramTypes()
  {
    Vector<String> diagramIds = new Vector<>();
    for (IDiagramType diagramType : GraphitiUi.getExtensionManager().getDiagramTypes())
    {
      diagramIds.add(diagramType.getId());
    }

    return diagramIds.toArray(new String[] {});
  }

  protected String getInitialValue()
  {
    // Get last choice
    IDialogSettings dialogSettings = DawnGraphitiUIPlugin.getDefault().getDialogSettings();
    String selType = dialogSettings.get(SELECTED_TYPE);
    List<String> asList = Arrays.asList(comboBox.getItems());
    if (asList.contains(selType))
    {
      return selType;
    }
    else if (asList.contains(DEFAULT_TYPE))
    {
      return DEFAULT_TYPE;
    }
    return null;
  }

  public String getText()
  {
    return comboBox.getText();
  }
}

Back to the top