Skip to main content
summaryrefslogtreecommitdiffstats
blob: f509a79c493a8789999524ec9e4115c5b0c57d2b (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
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsdl.ui.internal.viewers;

import java.util.Iterator;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorPart;
import org.eclipse.wst.wsdl.Part;
import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin;
import org.eclipse.wst.wsdl.ui.internal.util.ComponentReferenceUtil;
import org.eclipse.wst.wsdl.ui.internal.viewers.widgets.InvokeDialogButton;
import org.w3c.dom.Element;

public class PartViewer extends NamedComponentViewer
{   
  protected CCombo componentNameCombo;
  protected CCombo referenceKindCombo; 
  protected Label componentNameLabel;
  InvokeDialogButton button;
//  Button importButton;
  

  public PartViewer(Composite parent, IEditorPart editorPart)
  {
    super(parent, editorPart);    
  } 

  protected String getHeadingText()
  {
    return WSDLEditorPlugin.getWSDLString("_UI_LABEL_PART");  //$NON-NLS-1$
  } 

  public boolean isObjectExtensible()
  {
    return false;
  }
    
  protected Composite populatePrimaryDetailsSection(Composite parent)
  {
    Composite composite = super.populatePrimaryDetailsSection(parent);
     
    flatViewUtility.createLabel(composite, WSDLEditorPlugin.getWSDLString("_UI_LABEL_REFERENCE_KIND")); //$NON-NLS-1$
    referenceKindCombo = flatViewUtility.createCComboBox(composite);
    referenceKindCombo.add("element");
    referenceKindCombo.add("type");
    referenceKindCombo.setText("type");
    referenceKindCombo.addListener(SWT.Modify, this);

    flatViewUtility.createLabel(composite, ""); 
    
    componentNameLabel = flatViewUtility.createLabel(composite, WSDLEditorPlugin.getWSDLString("_UI_LABEL_ELEMENT"));   //$NON-NLS-1$

    componentNameCombo = flatViewUtility.createCComboBox(composite);
    componentNameCombo.addListener(SWT.Modify, this);
    componentNameCombo.addSelectionListener(this);

    button = new InvokeDialogButton(composite, getInput());
    
    return composite;
  }  
          
  protected void update()
  {                    
    try
    {
      Part part = (Part)input;
      boolean isType = ComponentReferenceUtil.isType(part);
      String value = ComponentReferenceUtil.getPartComponentReference(part);

      // update the combo-box content
      //
      componentNameCombo.removeAll(); 
      List compList = ComponentReferenceUtil.getComponentNameList(part, isType);
      if (compList != null)
      {
        for (Iterator iterator =  compList.iterator(); iterator.hasNext();)
        {
          componentNameCombo.add((String)iterator.next());
        }
      } 
      
      if (isType)
      {                                                 
        referenceKindCombo.setText("type");
        componentNameLabel.setText(WSDLEditorPlugin.getWSDLString("_UI_LABEL_TYPE"));  //$NON-NLS-1$
        componentNameCombo.setText(value != null ? value : "");
        button.setReferenceKind("type");
      }
      else
      {
        referenceKindCombo.setText("element");
        componentNameLabel.setText(WSDLEditorPlugin.getWSDLString("_UI_LABEL_ELEMENT"));  //$NON-NLS-1$
        componentNameCombo.setText(value != null ? value : "");
        button.setReferenceKind("element");
      }                                                        
      button.setInput(input);
      button.setEditor(editorPart);
      super.update();  
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }       
      
     
  protected void handleEventHelper(Element element, Event event)
  {  
    super.handleEventHelper(element, event);
    if (event.type == SWT.Modify)
    {  
      if (event.widget == referenceKindCombo)
      {                        
        // TODO... I have no idea why we need to use a delayed runnable to get 
        // updating working properly .... this is something we need to revisit
        DelayedRenameRunnable runnable = new DelayedRenameRunnable((Part)input);
        Display.getCurrent().asyncExec(runnable);  
      } 
    }
  }      

  protected class DelayedRenameRunnable implements Runnable
  {                       
    Part part;

    DelayedRenameRunnable(Part part)
    {
      this.part = part;
    }

    public void run()                  
    {                                                               
      boolean isType = referenceKindCombo.getText().equals("type");
      ComponentReferenceUtil.setComponentReference(part, isType, null);    
    }
  }  

  public void doWidgetSelected(SelectionEvent e)
  {
    if (e.widget == componentNameCombo)
    {                                                      
      Part part = (Part)input;
      boolean isType = referenceKindCombo.getText().equals("type");
      ComponentReferenceUtil.setComponentReference(part, isType, componentNameCombo.getText());          
    }
  } 
}

Back to the top