Skip to main content
summaryrefslogtreecommitdiffstats
blob: 20c4a361298d1bcfd963c9b655fcf0a115ed6225 (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
/*******************************************************************************
 * Copyright (c) 2001, 2008 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.asd.design.editparts;

import java.util.List;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.Panel;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.swt.graphics.Color;
import org.eclipse.wst.wsdl.ui.internal.asd.design.DesignViewGraphicsConstants;
import org.eclipse.wst.wsdl.ui.internal.asd.design.directedit.LabelCellEditorLocator;
import org.eclipse.wst.wsdl.ui.internal.asd.design.directedit.LabelEditManager;
import org.eclipse.wst.wsdl.ui.internal.asd.design.editpolicies.ASDLabelDirectEditPolicy;
import org.eclipse.wst.wsdl.ui.internal.asd.design.editpolicies.ASDSelectionEditPolicy;
import org.eclipse.wst.wsdl.ui.internal.asd.design.figures.ListFigure;
import org.eclipse.wst.wsdl.ui.internal.asd.facade.IOperation;
import org.eclipse.wst.wsdl.ui.internal.asd.outline.ITreeElement;


public class OperationEditPart extends BaseEditPart implements INamedEditPart
{ 
  protected Figure contentPane;
  protected Label label;
  private Color unselectedColor;
  private Figure labelHolder;
  
  public OperationEditPart()
  {
  }

  protected IFigure createFigure()
  {
    Figure figure = new Figure();
    figure.setBackgroundColor(DesignViewGraphicsConstants.tableOperationHeadingColor);
    ToolbarLayout toolbarLayout = new ToolbarLayout(false);   
    toolbarLayout.setStretchMinorAxis(true);   
    toolbarLayout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
    figure.setLayoutManager(toolbarLayout);
    
    labelHolder = new Panel() {
      public void paint(Graphics graphics) {
        super.paint(graphics);
        Rectangle r = getBounds();
        // bug146932
        paintFocusCursor(new Rectangle(r.x, r.y, r.width, r.height), graphics);
      }
    };
    labelHolder.setBackgroundColor(DesignViewGraphicsConstants.tableOperationHeadingColor);
    labelHolder.setLayoutManager(new ToolbarLayout(true));
    figure.add(labelHolder);
    
    label = new Label("Operation"); //$NON-NLS-1$
//    label.setFont(DesignViewGraphicsConstants.smallBoldFont);
    label.setBorder(new MarginBorder(2, 2,2,2));
    label.setTextAlignment(Label.LEFT);  
    labelHolder.add(label);
    
    
    contentPane = new ListFigure();  
    ToolbarLayout toolbarLayout2 = new ToolbarLayout(false);
    toolbarLayout2.setStretchMinorAxis(true);
    contentPane.setLayoutManager(toolbarLayout2);
    figure.add(contentPane);
 
    // rmah: The block of code below has been moved from refreshVisuals().  We're
    // assuming the read-only state of the EditPart will never change once the
    // EditPart has been created.
    if (isReadOnly()) {
    	label.setForegroundColor(DesignViewGraphicsConstants.readOnlyLabelColor);
   	    figure.setBackgroundColor(DesignViewGraphicsConstants.readOnlyTableOperationHeadingColor);
   	    labelHolder.setBackgroundColor(DesignViewGraphicsConstants.readOnlyTableOperationHeadingColor);
    }
    else {
    	label.setForegroundColor(ColorConstants.black);
 	    figure.setBackgroundColor(DesignViewGraphicsConstants.tableOperationHeadingColor);
   	    labelHolder.setBackgroundColor(DesignViewGraphicsConstants.tableOperationHeadingColor);
    }
    
    return figure;
  }
  
  protected void createEditPolicies()
  {
      super.createEditPolicies();
	  installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new ASDLabelDirectEditPolicy());
	  installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new ASDSelectionEditPolicy());
  }
  
  private DirectEditManager manager;
  public void performDirectEdit(Point cursorLocation){
	  Rectangle textArea = getLabelFigure().getBounds();
	  textArea.width = getFigure().getBounds().width;
	  if (!isFileReadOnly() && (cursorLocation == null || hitTest(textArea, cursorLocation) && !isReadOnly())) {
		  manager = new LabelEditManager(this, new LabelCellEditorLocator(this, cursorLocation));
		  manager.show();
	  }
    else if (getFigure() instanceof Figure && hitTestFigure((Figure) getFigure(), cursorLocation) && isReadOnly()) {
      doOpenNewEditor();    
    }
  }
  
  public void performRequest(Request req) {
	  if (req.getType().equals(RequestConstants.REQ_DIRECT_EDIT)) {
		  performDirectEdit(null);
	  }
  }
  
  public Label getLabelFigure() {
	  return label;
  }
  
  protected void refreshVisuals()
  {   
    super.refreshVisuals();
    IOperation operation = (IOperation)getModel();
    label.setText(operation.getName());
    
    if (operation instanceof ITreeElement) {
    	label.setIcon(((ITreeElement) operation).getImage());
    }
  }
  
  public IFigure getContentPane()
  {
    return contentPane;
  }

  protected List getModelChildren()
  {
    IOperation theOperation = (IOperation)getModel();
    return theOperation.getMessages();
  }
  
  public void addFeedback() {
	  unselectedColor = labelHolder.getBackgroundColor();
//	  getFigure().setBackgroundColor(DesignViewGraphicsConstants.tableCellSelectionColor);
	  labelHolder.setBackgroundColor(DesignViewGraphicsConstants.tableCellSelectionColor);
  }
  
  public void removeFeedback() {
	  if (unselectedColor != null) {
		  labelHolder.setBackgroundColor(unselectedColor);
	  }
  }
}

Back to the top