blob: 35f448670853aa190bddcccc0d42fe42f1061fc5 [file] [log] [blame]
/*******************************************************************************
* 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.xsd.ui.internal.graph.editparts;
import java.util.List;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.wst.xsd.ui.internal.graph.XSDChildUtility;
import org.eclipse.wst.xsd.ui.internal.graph.XSDGraphUtil;
import org.eclipse.wst.xsd.ui.internal.graph.editpolicies.ComponentNameDirectEditManager;
import org.eclipse.wst.xsd.ui.internal.graph.editpolicies.SelectionHandlesEditPolicyImpl;
import org.eclipse.wst.xsd.ui.internal.graph.editpolicies.SimpleDirectEditPolicy;
import org.eclipse.wst.xsd.ui.internal.graph.figures.ExpandableGraphNodeFigure;
import org.eclipse.wst.xsd.ui.internal.graph.figures.FillLayout;
import org.eclipse.wst.xsd.ui.internal.graph.figures.GraphNodeFigure;
import org.eclipse.wst.xsd.ui.internal.graph.figures.RoundedLineBorder;
import org.eclipse.xsd.XSDModelGroupDefinition;
public class RootModelGroupDefinitionEditPart extends ExpandableGraphNodeEditPart
{
public Label label;
protected SimpleDirectEditPolicy simpleDirectEditPolicy = new SimpleDirectEditPolicy();
protected GraphNodeFigure createGraphNodeFigure()
{
ExpandableGraphNodeFigure figure = new ExpandableGraphNodeFigure();
figure.getOutlinedArea().setBorder(new RoundedLineBorder(1, 6));
figure.getOutlinedArea().setLayoutManager(new FillLayout());
figure.getOutlinedArea().setFill(true);
label = new Label();
label.setFont(mediumBoldFont);
label.setBorder(new MarginBorder(5, 8, 5, 8));
figure.getIconArea().add(label);
return figure;
}
protected void refreshVisuals()
{
super.refreshVisuals();
XSDModelGroupDefinition mgd = (XSDModelGroupDefinition)getModel();
String name = mgd.getResolvedModelGroupDefinition().getName();
label.setText(name);
if (XSDGraphUtil.isEditable(getModel()))
{
figure.setForegroundColor(elementBorderColor);
label.setForegroundColor(elementBorderColor);
}
else
{
figure.setForegroundColor(readOnlyBorderColor);
label.setForegroundColor(readOnlyBorderColor);
}
}
protected List getModelChildrenHelper()
{
return XSDChildUtility.getModelChildren(getModel());
}
protected void createEditPolicies()
{
SelectionHandlesEditPolicyImpl policy = new SelectionHandlesEditPolicyImpl();
installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, policy);
installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, simpleDirectEditPolicy);
}
protected void performDirectEdit()
{
ComponentNameDirectEditManager manager = new ComponentNameDirectEditManager(this, label, ((XSDModelGroupDefinition)getModel()).getResolvedModelGroupDefinition());
simpleDirectEditPolicy.setDelegate(manager);
manager.show();
}
public void performRequest(Request request)
{
if (request.getType() == RequestConstants.REQ_DIRECT_EDIT)
{
if (XSDGraphUtil.isEditable(getModel()))
{
performDirectEdit();
}
}
}
}