Skip to main content
summaryrefslogtreecommitdiffstats
blob: 964f38a045568480426a8d197f47cba6ca66e446 (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
/*******************************************************************************
 * Copyright (c) 2001, 2006 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 org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.requests.DirectEditRequest;
import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.wst.wsdl.ui.internal.adapters.WSDLBaseAdapter;
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.BoxComponentFigure;
import org.eclipse.wst.wsdl.ui.internal.asd.design.layouts.ColumnData;

public abstract class AbstractBoxtEditPart extends BaseEditPart implements INamedEditPart
{
  protected ColumnData columnData = new ColumnData();
  protected BoxComponentFigure figure;
  
  protected IFigure createFigure()
  {
    figure = new BoxComponentFigure();
    figure.setBorder(new LineBorder(1));
    ToolbarLayout toolbarLayout = new ToolbarLayout();
    toolbarLayout.setStretchMinorAxis(true);
    // toolbarLayout.setMinorAlignment(ToolbarLayout.ALIGN_BOTTOMRIGHT);
    figure.setLayoutManager(toolbarLayout);
    // if(isScrollable())
    // figure.setScrollingActionListener(this);
    return figure;
  }

  public IFigure getContentPane()
  {
    return figure.getContentPane();
  }

  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){
	  if (cursorLocation == null ||  hitTestFigure(figure.getHeadingFigure(), cursorLocation) && !isReadOnly()) {
		  manager = new LabelEditManager(this, new LabelCellEditorLocator(this, cursorLocation));
		  manager.show();
	  }
    else if ((hitTest(figure.getLabel(), cursorLocation) ||
        hitTestFigure(figure.getHeadingFigure(), cursorLocation)) && isReadOnly()) {
      doOpenNewEditor();
    }
  }
  
  public void performRequest(Request req) {
	  if (req.getType().equals(RequestConstants.REQ_DIRECT_EDIT)) {
		  Point location = null;
		  if (req instanceof DirectEditRequest) {
			  location = ((DirectEditRequest) req).getLocation();			  
		  }
		  performDirectEdit(location);
	  }
  }
  
  public Label getLabelFigure() {
	  return figure.getLabel();
  }

  protected void refreshChildren()
  {
    super.refreshChildren();
    // getFigure().invalidateTree();
  }

  protected void refreshVisuals()
  {
    super.refreshVisuals();
    WSDLBaseAdapter box = (WSDLBaseAdapter) getModel();
    figure.headingFigure.setIsReadOnly(box.isReadOnly());
    figure.getLabel().setText(box.getName());
  }

  public void addFeedback()
  {
	  LineBorder boxFigureLineBorder = (LineBorder) figure.getBorder();
	  boxFigureLineBorder.setWidth(2);
//	  boxFigureLineBorder.setColor(ColorConstants.darkBlue);
	  figure.setSelected(true);
	  figure.repaint();
  }

  public void removeFeedback()
  {
	  LineBorder boxFigureLineBorder = (LineBorder) figure.getBorder();
	  boxFigureLineBorder.setWidth(1);
	  boxFigureLineBorder.setColor(ColorConstants.black);
	  figure.setSelected(false);
	  figure.repaint();
  }

  public ColumnData getColumnData()
  {
    return columnData;
  }
}

Back to the top