Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » WrappingLabel multiline when editing
WrappingLabel multiline when editing [message #484110] Fri, 04 September 2009 10:44 Go to next message
Marc Mising name is currently offline Marc Mising nameFriend
Messages: 193
Registered: July 2009
Location: Valencia, Spain
Senior Member
Hello!

I want to know how to indicate that the wrapping label is multiline when
it was in editing mode.

I try to set the attribute isWrap to true: "label.setTextWrap(true)", but
when I edit the content, I don't know how to get a new line...

Can anybody helps me please?

Thanks!!!
Marc
Re: WrappingLabel multiline when editing [message #484141 is a reply to message #484110] Fri, 04 September 2009 12:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier.marot.logica.com

Hi Marc,
I've got the same issue, so I can add some precision :
the label adds a new line automatically when the first reaches the maximum
width, but "ctrl + enter" doesn't add a line return (from what I read in
another topic, it actually should).

I'm trying to fix that up, I'll tell you if it is successful.

Regards.
Re: WrappingLabel multiline when editing [message #484177 is a reply to message #484110] Fri, 04 September 2009 13:47 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Marc,

See http://www.eclipse.org/newsportal/article.php?id=18921&g roup=eclipse.modeling.gmf

-----------------
Alex Shatalin
Re: WrappingLabel multiline when editing [message #485573 is a reply to message #484110] Sun, 13 September 2009 19:19 Go to previous messageGo to next message
Ugo Sangiorgi is currently offline Ugo SangiorgiFriend
Messages: 44
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------080806040207050609020106
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

One thing that worked for me was, instead of editing the label directly
at the diagram, open a popup with the label, so you can edit like a
normal text.

I'm planning to add rich text funcionality later, so if interacting with
a dialog is not a issue for your users, give this a try:


First create a Multi-line dialog (there is an example attached),
Then replace the performDirectEdit method at the editpart's labels you
want and launch it right away:

/**
* @generated NOT
*/
protected void performDirectEdit() {

EDataTypeValueHandler valueHandler = new
EDataTypeValueHandler(EcorePackage.eINSTANCE.getEString());
InputDialog dialog = new
MultiLineInputDialog(getViewer().getControl().getShell(),
EMFEditUIPlugin.INSTANCE.getString("_UI_FeatureEditorDialog_title ",
new Object [] { "Title" }), "Enter
value:",valueHandler.toString(getEditText()),valueHandler);

if (dialog.open() == Window.OK) {
EAttribute feature = XXXPackage.eINSTANCE.getXXX();
getEditingDomain().getCommandStack().execute(SetCommand.crea te(getEditingDomain(),
((View) getParent().getModel()).getElement(), feature , dialog.getValue()));

}

}

Good luck

Marc escreveu:
> Hello!
>
> I want to know how to indicate that the wrapping label is multiline when
> it was in editing mode.
>
> I try to set the attribute isWrap to true: "label.setTextWrap(true)",
> but when I edit the content, I don't know how to get a new line...
>
> Can anybody helps me please?
>
> Thanks!!!
> Marc
>


--------------080806040207050609020106
Content-Type: text/x-java;
name="EDataTypeValueHandler.java"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="EDataTypeValueHandler.java"

cGFja2FnZSBici5wdWMubW9saWMuZGlhZ3JhbS5tdWx0aWxpbmU7CgppbXBv cnQgb3JnLmVj
bGlwc2UuZW1mLmNvbW1vbi51dGlsLkRpYWdub3N0aWM7CmltcG9ydCBvcmcu ZWNsaXBzZS5l
bWYuZWNvcmUuRURhdGFUeXBlOwppbXBvcnQgb3JnLmVjbGlwc2UuZW1mLmVj b3JlLnV0aWwu
RGlhZ25vc3RpY2lhbjsKaW1wb3J0IG9yZy5lY2xpcHNlLmVtZi5lY29yZS51 dGlsLkVjb3Jl
VXRpbDsKaW1wb3J0IG9yZy5lY2xpcHNlLmpmYWNlLmRpYWxvZ3MuSUlucHV0 VmFsaWRhdG9y
OwppbXBvcnQgb3JnLmVjbGlwc2UuamZhY2Uudmlld2Vycy5JQ2VsbEVkaXRv clZhbGlkYXRv
cjsKCnB1YmxpYyBjbGFzcyBFRGF0YVR5cGVWYWx1ZUhhbmRsZXIgaW1wbGVt ZW50cyBJQ2Vs
bEVkaXRvclZhbGlkYXRvciwgSUlucHV0VmFsaWRhdG9yCnsKICAgIHByb3Rl Y3RlZCBFRGF0
YVR5cGUgZURhdGFUeXBlOwoKICAgIHB1YmxpYyBFRGF0YVR5cGVWYWx1ZUhh bmRsZXIoRURh
dGFUeXBlIGVEYXRhVHlwZSkKICAgIHsKICAgICAgdGhpcy5lRGF0YVR5cGUg PSBlRGF0YVR5
cGU7CiAgICB9CgogICAgcHVibGljIFN0cmluZyBpc1ZhbGlkKE9iamVjdCBv YmplY3QpCiAg
ICB7CiAgICAgIE9iamVjdCB2YWx1ZTsKICAgICAgdHJ5CiAgICAgIHsKICAg ICAgICB2YWx1
ZSA9IGVEYXRhVHlwZS5nZXRFUGFja2FnZSgpLmdldEVGYWN0b3J5SW5zdGFu Y2UoKS5jcmVh
dGVGcm9tU3RyaW5nKGVEYXRhVHlwZSwgKFN0cmluZylvYmplY3QpOwogICAg ICB9CiAgICAg
IGNhdGNoIChFeGNlcHRpb24gZXhjZXB0aW9uKQogICAgICB7CiAgICAgICAg U3RyaW5nIG1l
c3NhZ2UgPSBleGNlcHRpb24uZ2V0Q2xhc3MoKS5nZXROYW1lKCk7CiAgICAg ICAgaW50IGlu
ZGV4ID0gbWVzc2FnZS5sYXN0SW5kZXhPZignLicpOwogICAgICAgIGlmIChp bmRleCA+PSAw
KQogICAgICAgIHsKICAgICAgICAgIG1lc3NhZ2UgPSBtZXNzYWdlLnN1YnN0 cmluZyhpbmRl
eCArIDEpOwogICAgICAgIH0KICAgICAgICBpZiAoZXhjZXB0aW9uLmdldExv Y2FsaXplZE1l
c3NhZ2UoKSAhPSBudWxsKQogICAgICAgIHsKICAgICAgICAgIG1lc3NhZ2Ug PSBtZXNzYWdl
ICsgIjogIiArIGV4Y2VwdGlvbi5nZXRMb2NhbGl6ZWRNZXNzYWdlKCk7CiAg ICAgICAgfQog
ICAgICAgIHJldHVybiBtZXNzYWdlOwogICAgICB9CiAgICAgIERpYWdub3N0 aWMgZGlhZ25v
c3RpYyA9IERpYWdub3N0aWNpYW4uSU5TVEFOQ0UudmFsaWRhdGUoZURhdGFU eXBlLCB2YWx1
ZSk7CiAgICAgIGlmIChkaWFnbm9zdGljLmdldFNldmVyaXR5KCkgPT0gRGlh Z25vc3RpYy5P
SykKICAgICAgewogICAgICAgIHJldHVybiBudWxsOwogICAgICB9CiAgICAg IGVsc2UKICAg
ICAgewogICAgICAgIHJldHVybiAoZGlhZ25vc3RpYy5nZXRDaGlsZHJlbigp LmdldCgwKSku
Z2V0TWVzc2FnZSgpLnJlcGxhY2VBbGwoIiciLCInJyIpLnJlcGxhY2VBbGwo IlxceyIsICIn
eyciKTsgLy8gfX0KICAgICAgfQogICAgfQoKICAgIHB1YmxpYyBTdHJpbmcg aXNWYWxpZChT
dHJpbmcgdGV4dCkKICAgIHsKICAgICAgcmV0dXJuIGlzVmFsaWQoKE9iamVj dCl0ZXh0KTsK
ICAgIH0KCiAgICBwdWJsaWMgT2JqZWN0IHRvVmFsdWUoU3RyaW5nIHN0cmlu ZykKICAgIHsK
ICAgICAgcmV0dXJuIEVjb3JlVXRpbC5jcmVhdGVGcm9tU3RyaW5nKGVEYXRh VHlwZSwgc3Ry
aW5nKTsKICAgIH0KCiAgICBwdWJsaWMgU3RyaW5nIHRvU3RyaW5nKE9iamVj dCB2YWx1ZSkK
ICAgIHsKICAgICAgU3RyaW5nIHJlc3VsdCA9IEVjb3JlVXRpbC5jb252ZXJ0 VG9TdHJpbmco
ZURhdGFUeXBlLCB2YWx1ZSk7CiAgICAgIHJldHVybiByZXN1bHQgPT0gbnVs bCA/ICIiIDog
cmVzdWx0OwogICAgfQogICAgCiAgfQ==
--------------080806040207050609020106
Content-Type: text/x-java;
name="InputDialog.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="InputDialog.java"

package br.puc.molic.diagram.multiline;

/**
* <copyright>
*
* Copyright (c) 2000-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 - Initial API and implementation
*
* </copyright>
*
* $Id: InputDialog.java,v 1.4 2008/05/07 19:08:40 emerks Exp $
*/


import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
* A simple input dialog for soliciting an input string from the user.
* <p>
* This concrete dialog class can be instantiated as is, or further subclassed as
* required.
* </p>
* <p>
* This class is cloned from <code>org.eclipse.jface.dialogs.InputDialog</code>,
* with minimal changes required for extensibility. A bugzilla has been filed to request
* a more flexible implementation. If it is fixed, this class will go away.
* </p>
*/
public class InputDialog extends Dialog {
/**
* The title of the dialog.
*/
private String title;

/**
* The message to display, or <code>null</code> if none.
*/
private String message;

/**
* The input value; the empty string by default.
*/
private String value = "";//$NON-NLS-1$

/**
* The input validator, or <code>null</code> if none.
*/
private IInputValidator validator;

/**
* OK button widget.
*/
private Button okButton;

/**
* Input text widget.
*/
private Text text;

/**
* Error message label widget.
*/
private Text errorMessageText;

/**
* Error message string.
*/
private String errorMessage;

/**
* Creates an input dialog with OK and Cancel buttons. Note that the dialog
* will have no visual representation (no widgets) until it is told to open.
* <p>
* Note that the <code>open</code> method blocks for input dialogs.
* </p>
*
* @param parentShell
* the parent shell, or <code>null</code> to create a top-level
* shell
* @param dialogTitle
* the dialog title, or <code>null</code> if none
* @param dialogMessage
* the dialog message, or <code>null</code> if none
* @param initialValue
* the initial input value, or <code>null</code> if none
* (equivalent to the empty string)
* @param validator
* an input validator, or <code>null</code> if none
*/
public InputDialog(Shell parentShell, String dialogTitle,
String dialogMessage, String initialValue, IInputValidator validator) {
super(parentShell);
this.title = dialogTitle;
message = dialogMessage;
if (initialValue == null) {
value = "";//$NON-NLS-1$
} else {
value = initialValue;
}
this.validator = validator;
}

/*
* (non-Javadoc) Method declared on Dialog.
*/
@Override
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
value = text.getText();
} else {
value = null;
}
super.buttonPressed(buttonId);
}

/*
* (non-Javadoc)
*
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.s wt.widgets.Shell)
*/
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
if (title != null) {
shell.setText(title);
}
}

/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(o rg.eclipse.swt.widgets.Composite)
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
// create OK and Cancel buttons by default
okButton = createButton(parent, IDialogConstants.OK_ID,
IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, false);
//do this here because setting the text will set enablement on the OK
// button
text.setFocus();
if (value != null) {
text.setText(value);
text.selectAll();
}
}

/*
* (non-Javadoc) Method declared on Dialog.
*/
@Override
protected Control createDialogArea(Composite parent) {
// create composite
Composite composite = (Composite) super.createDialogArea(parent);
// create message
if (message != null) {
Label label = new Label(composite, SWT.WRAP);
label.setText(message);
GridData data = new GridData(GridData.GRAB_HORIZONTAL
/* | GridData.GRAB_VERTICAL */ | GridData.HORIZONTAL_ALIGN_FILL
| GridData.VERTICAL_ALIGN_CENTER);
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSA GE_AREA_WIDTH);
label.setLayoutData(data);
label.setFont(parent.getFont());
}
/*
text = new Text(composite, SWT.SINGLE | SWT.BORDER);
text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
| GridData.HORIZONTAL_ALIGN_FILL));
*/
text = createText(composite);
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
validateInput();
}
});
errorMessageText = new Text(composite, SWT.READ_ONLY);
errorMessageText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
| GridData.HORIZONTAL_ALIGN_FILL));
errorMessageText.setBackground(errorMessageText.getDisplay()
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
// Set the error message text
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=66292
setErrorMessage(errorMessage);

applyDialogFont(composite);
return composite;
}

/**
* Creates the text widget for the user's input.
*
* @return the text widget
*/
protected Text createText(Composite composite) {
Text text = new Text(composite, SWT.SINGLE | SWT.BORDER);
text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
| GridData.HORIZONTAL_ALIGN_FILL));
return text;
}

/**
* Returns the error message label.
*
* @return the error message label
* @deprecated use setErrorMessage(String) instead
*/
@Deprecated
protected Label getErrorMessageLabel() {
return null;
}

/**
* Returns the OK button.
*
* @return the OK button
*/
protected Button getOkButton() {
return okButton;
}

/**
* Returns the text area.
*
* @return the text area
*/
protected Text getText() {
return text;
}

/**
* Returns the validator.
*
* @return the validator
*/
protected IInputValidator getValidator() {
return validator;
}

/**
* Returns the string typed into this input dialog.
*
* @return the input string
*/
public String getValue() {
return value;
}

/**
* Validates the input.
* <p>
* The default implementation of this framework method delegates the request
* to the supplied input validator object; if it finds the input invalid,
* the error message is displayed in the dialog's message line. This hook
* method is called whenever the text changes in the input field.
* </p>
*/
protected void validateInput() {
String errorMessage = null;
if (validator != null) {
errorMessage = validator.isValid(text.getText());
}
// Bug 16256: important not to treat "" (blank error) the same as null
// (no error)
setErrorMessage(errorMessage);
}

/**
* Sets or clears the error message.
* If not <code>null</code>, the OK button is disabled.
*
* @param errorMessage
* the error message, or <code>null</code> to clear
* @since 3.0
*/
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
if (errorMessageText != null && !errorMessageText.isDisposed()) {
errorMessageText.setText(errorMessage == null ? "" : errorMessage); //$NON-NLS-1$
errorMessageText.getParent().update();
// Access the OK button by id, in case clients have overridden button creation.
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=113643
Control button = getButton(IDialogConstants.OK_ID);
if (button != null) {
button.setEnabled(errorMessage == null);
}
}
}
}


--------------080806040207050609020106
Content-Type: text/x-java;
name="MultiLineInputDialog.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="MultiLineInputDialog.java"

package br.puc.molic.diagram.multiline;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


public class MultiLineInputDialog extends InputDialog
{
public MultiLineInputDialog(Shell parentShell, String title, String message, String initialValue, IInputValidator validator)
{
super(parentShell, title, message, initialValue, validator);
setShellStyle(getShellStyle() | SWT.RESIZE);
}

@Override
protected Text createText(Composite composite)
{
Text text = new Text(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
data.heightHint = 5 * text.getLineHeight();
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_W IDTH);
text.setLayoutData(data);
return text;
}
}

--------------080806040207050609020106
Content-Type: text/x-java;
name="SceneDialogueEditPart.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="SceneDialogueEditPart.java"

/*
* Teste de nota de copyright do Molic
*/
package br.puc.molic.diagram.edit.parts;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.draw2d.AncestorListener;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.ui.EMFEditUIPlugin;
import org.eclipse.emf.edit.ui.provider.PropertyDescriptor;

import org.eclipse.emf.transaction.RunnableWithResult;
import org.eclipse.gef.AccessibleEditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.handles.MoveHandle;
import org.eclipse.gef.handles.NonResizableHandleKit;
import org.eclipse.gef.requests.DirectEditRequest;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.gmf.runtime.common.core.util.Log;
import org.eclipse.gmf.runtime.common.core.util.Trace;
import org.eclipse.gmf.runtime.common.ui.contentassist.ContentAssis tantHelper;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEdi tStatus;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEdit Status;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOpti ons;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserServ ice;
import org.eclipse.gmf.runtime.diagram.core.DiagramEditingDomainFac tory;
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEdit Part;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditP art;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectE ditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIDebugOp tions;
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIPlugin;
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIStatusC odes;
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry ;
import org.eclipse.gmf.runtime.diagram.ui.label.ILabelDelegate;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalVie wer;
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants ;
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManag er;
import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticPars er;
import org.eclipse.gmf.runtime.gef.ui.internal.parts.TextCellEditor Ex;
import org.eclipse.gmf.runtime.gef.ui.internal.parts.WrapTextCellEd itor;
import org.eclipse.gmf.runtime.notation.FontStyle;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.runtime.notation.provider.NodeItemProvider;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IInputValidator;

import org.eclipse.jface.resource.DeviceResourceException;
import org.eclipse.jface.resource.FontDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor ;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellEditorValidator;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.part.CellEditorActionHandler;

import br.puc.molic.MolicPackage;
import br.puc.molic.Scene;
import br.puc.molic.diagram.edit.policies.MolicTextSelectionEditPol icy;
import br.puc.molic.diagram.multiline.EDataTypeValueHandler;
import br.puc.molic.diagram.multiline.InputDialog;
import br.puc.molic.diagram.multiline.MultiLineInputDialog;
import br.puc.molic.diagram.part.MolicDiagramEditorPlugin;
import br.puc.molic.diagram.part.MolicVisualIDRegistry;
import br.puc.molic.diagram.providers.MolicElementTypes;
import br.puc.molic.diagram.providers.MolicParserProvider;
import br.puc.molic.provider.SceneItemProvider;

/**
* @generated
*/
public class SceneDialogueEditPart extends CompartmentEditPart implements
ITextAwareEditPart {

/**
* @generated
*/
public static final int VISUAL_ID = 5005;

/**
* @generated
*/
private DirectEditManager manager;

/**
* @generated
*/
private IParser parser;

/**
* @generated
*/
private List parserElements;

/**
* @generated
*/
private String defaultText;

/**
* @generated
*/
public SceneDialogueEditPart(View view) {
super(view);
}

/**
* @generated
*/
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,
new MolicTextSelectionEditPolicy());
installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE,
new LabelDirectEditPolicy());
installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
new NonResizableEditPolicy() {

protected List createSelectionHandles() {
List handles = new ArrayList();
NonResizableHandleKit.addMoveHandle(
(GraphicalEditPart) getHost(), handles);
((MoveHandle) handles.get(0)).setBorder(null);
return handles;
}

public Command getCommand(Request request) {
return null;
}

public boolean understandsRequest(Request request) {
return false;
}
});
}

/**
* @generated
*/
protected String getLabelTextHelper(IFigure figure) {
if (figure instanceof WrappingLabel) {
return ((WrappingLabel) figure).getText();
} else {
return ((Label) figure).getText();
}
}

/**
* @generated
*/
protected void setLabelTextHelper(IFigure figure, String text) {
if (figure instanceof WrappingLabel) {
((WrappingLabel) figure).setText(text);
} else {
((Label) figure).setText(text);
}
}

/**
* @generated
*/
protected Image getLabelIconHelper(IFigure figure) {
if (figure instanceof WrappingLabel) {
return ((WrappingLabel) figure).getIcon();
} else {
return ((Label) figure).getIcon();
}
}

/**
* @generated
*/
protected void setLabelIconHelper(IFigure figure, Image icon) {
if (figure instanceof WrappingLabel) {
((WrappingLabel) figure).setIcon(icon);
} else {
((Label) figure).setIcon(icon);
}
}

/**
* @generated
*/
public void setLabel(WrappingLabel figure) {
unregisterVisuals();
setFigure(figure);
defaultText = getLabelTextHelper(figure);
registerVisuals();
refreshVisuals();
}

/**
* @generated
*/
protected List getModelChildren() {
return Collections.EMPTY_LIST;
}

@Override
protected void fireSelectionChanged() {
super.fireSelectionChanged();
if (getSelected() == 2) {
performDirectEdit();

//org.eclipse.emf.edit.ui.provider.PropertyDescriptor;
}
}

/**
* @generated
*/
public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
return null;
}

/**
* @generated
*/
protected EObject getParserElement() {
return resolveSemanticElement();
}

/**
* @generated
*/
protected Image getLabelIcon() {
return null;
}

/**
* @generated
*/
protected String getLabelText() {
String text = null;
EObject parserElement = getParserElement();
if (parserElement != null && getParser() != null) {
text = getParser().getPrintString(
new EObjectAdapter(parserElement),
getParserOptions().intValue());
}
if (text == null || text.length() == 0) {
text = defaultText;
}
return text;
}

/**
* @generated
*/
public void setLabelText(String text) {
setLabelTextHelper(getFigure(), text);
Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
if (pdEditPolicy instanceof MolicTextSelectionEditPolicy) {
((MolicTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
}
Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
if (sfEditPolicy instanceof MolicTextSelectionEditPolicy) {
((MolicTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
}
}

/**
* @generated
*/
public String getEditText() {
if (getParserElement() == null || getParser() == null) {
return ""; //$NON-NLS-1$
}
return getParser().getEditString(
new EObjectAdapter(getParserElement()),
getParserOptions().intValue());
}

/**
* @generated
*/
protected boolean isEditable() {
return getParser() != null;
}

/**
* @generated
*/
public ICellEditorValidator getEditTextValidator() {
return new ICellEditorValidator() {

public String isValid(final Object value) {
if (value instanceof String) {
final EObject element = getParserElement();
final IParser parser = getParser();
try {
IParserEditStatus valid = (IParserEditStatus) getEditingDomain()
.runExclusive(new RunnableWithResult.Impl() {

public void run() {
setResult(parser.isValidEditString(
new EObjectAdapter(element),
(String) value));
}
});
return valid.getCode() == ParserEditStatus.EDITABLE ? null
: valid.getMessage();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}

// shouldn't get here
return null;
}
};
}

/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(
new EObjectAdapter(getParserElement()));
}

/**
* @generated
*/
public ParserOptions getParserOptions() {
return ParserOptions.NONE;
}

/**
* @generated
*/
public IParser getParser() {
if (parser == null) {
parser = MolicParserProvider
.getParser(
MolicElementTypes.Scene_2007,
getParserElement(),
MolicVisualIDRegistry
.getType(br.puc.molic.diagram.edit.parts.SceneDialogueEditPa rt.VISUAL_ID));
}
return parser;
}

/**
* @generated NOT
*/
protected DirectEditManager getManager() {
if (manager == null) {
/*setManager(new TextDirectEditManager(this, TextDirectEditManager
.getTextCellEditorClass(this), MolicEditPartFactory
.getTextCellEditorLocator(this)));
*/

DialogueTextManager m = new DialogueTextManager(this,
WrapTextCellEditor.class, MolicEditPartFactory
.getTextCellEditorLocator(this));

setManager(m);
}
return manager;
}

/**
* @generated
*/
protected void setManager(DirectEditManager manager) {
this.manager = manager;
}

/**
* @generated NOT
*/
protected void performDirectEdit() {
String topic = ((Scene) ((View) getParent().getModel()).getElement()).getTopic();
EDataTypeValueHandler valueHandler = new EDataTypeValueHandler(EcorePackage.eINSTANCE.getEString());
InputDialog dialog = new MultiLineInputDialog(getViewer().getControl().getShell(),
EMFEditUIPlugin.INSTANCE.getString("_UI_FeatureEditorDialog_title ", new Object [] { "Scene "+topic, "dialogue" }),
"Enter the dialogue:",valueHandler.toString(getEditText()),valueHandler);

if (dialog.open() == Window.OK) {
EAttribute feature = MolicPackage.eINSTANCE.getScene_Dialogue();
getEditingDomain().getCommandStack().execute(SetCommand.crea te(getEditingDomain(), ((View) getParent().getModel()).getElement(), feature , dialog.getValue()));

}

}


/**
* @generated
*/
protected void performDirectEdit(Point eventLocation) {
if (getManager().getClass() == TextDirectEditManager.class) {
((TextDirectEditManager) getManager()).show(eventLocation
.getSWTPoint());
}
}

/**
* @generated
*/
private void performDirectEdit(char initialCharacter) {
if (getManager() instanceof TextDirectEditManager) {
((TextDirectEditManager) getManager()).show(initialCharacter);
} else {
performDirectEdit();
}
}

/**
* @generated
*/
protected void performDirectEditRequest(Request request) {
final Request theRequest = request;
try {
getEditingDomain().runExclusive(new Runnable() {

public void run() {
if (isActive() && isEditable()) {
if (theRequest
.getExtendedData()
.get(
RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
Character initialChar = (Character) theRequest
.getExtendedData()
.get(
RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
performDirectEdit(initialChar.charValue());
} else if ((theRequest instanceof DirectEditRequest)
&& (getEditText().equals(getLabelText()))) {
DirectEditRequest editRequest = (DirectEditRequest) theRequest;
performDirectEdit(editRequest.getLocation());
} else {
performDirectEdit();
}
}
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}

/**
* @generated
*/
protected void refreshVisuals() {
super.refreshVisuals();
refreshLabel();
refreshFont();
refreshFontColor();
refreshUnderline();
refreshStrikeThrough();
}

/**
* @generated
*/
protected void refreshLabel() {
setLabelTextHelper(getFigure(), getLabelText());
setLabelIconHelper(getFigure(), getLabelIcon());
Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
if (pdEditPolicy instanceof MolicTextSelectionEditPolicy) {
((MolicTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
}
Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
if (sfEditPolicy instanceof MolicTextSelectionEditPolicy) {
((MolicTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
}
}

/**
* @generated
*/
protected void refreshUnderline() {
FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(
NotationPackage.eINSTANCE.getFontStyle());
if (style != null && getFigure() instanceof WrappingLabel) {
((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline());
}
}

/**
* @generated
*/
protected void refreshStrikeThrough() {
FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(
NotationPackage.eINSTANCE.getFontStyle());
if (style != null && getFigure() instanceof WrappingLabel) {
((WrappingLabel) getFigure()).setTextStrikeThrough(style
.isStrikeThrough());
}
}

/**
* @generated
*/
protected void refreshFont() {
FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(
NotationPackage.eINSTANCE.getFontStyle());
if (style != null) {
FontData fontData = new FontData(style.getFontName(), style
.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL)
| (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
setFont(fontData);
}
}

/**
* @generated
*/
protected void setFontColor(Color color) {
getFigure().setForegroundColor(color);
}

/**
* @generated
*/
protected void addSemanticListeners() {
if (getParser() instanceof ISemanticParser) {
EObject element = resolveSemanticElement();
parserElements = ((ISemanticParser) getParser())
.getSemanticElementsBeingParsed(element);
for (int i = 0; i < parserElements.size(); i++) {
addListenerFilter(
"SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
}
} else {
super.addSemanticListeners();
}
}

/**
* @generated
*/
protected void removeSemanticListeners() {
if (parserElements != null) {
for (int i = 0; i < parserElements.size(); i++) {
removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
}
} else {
super.removeSemanticListeners();
}
}

/**
* @generated
*/
protected AccessibleEditPart getAccessibleEditPart() {
if (accessibleEP == null) {
accessibleEP = new AccessibleGraphicalEditPart() {

public void getName(AccessibleEvent e) {
e.result = getLabelTextHelper(getFigure());
}
};
}
return accessibleEP;
}

/**
* @generated
*/
private View getFontStyleOwnerView() {
return getPrimaryView();
}

/**
* @generated
*/
protected void addNotationalListeners() {
super.addNotationalListeners();
addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
}

/**
* @generated
*/
protected void removeNotationalListeners() {
super.removeNotationalListeners();
removeListenerFilter("PrimaryView"); //$NON-NLS-1$
}

/**
* @generated
*/
protected void handleNotificationEvent(Notification event) {
Object feature = event.getFeature();
if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(f eature)) {
Integer c = (Integer) event.getNewValue();
setFontColor(DiagramColorRegistry.getInstance().getColor(c)) ;
} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(
feature)) {
refreshUnderline();
} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough()
.equals(feature)) {
refreshStrikeThrough();
} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(
feature)
|| NotationPackage.eINSTANCE.getFontStyle_FontName().equals(
feature)
|| NotationPackage.eINSTANCE.getFontStyle_Bold()
.equals(feature)
|| NotationPackage.eINSTANCE.getFontStyle_Italic().equals(
feature)) {
refreshFont();
} else {
if (getParser() != null
&& getParser().isAffectingEvent(event,
getParserOptions().intValue())) {
refreshLabel();
}
if (getParser() instanceof ISemanticParser) {
ISemanticParser modelParser = (ISemanticParser) getParser();
if (modelParser.areSemanticElementsAffected(null, event)) {
removeSemanticListeners();
if (resolveSemanticElement() != null) {
addSemanticListeners();
}
refreshLabel();
}
}
}
super.handleNotificationEvent(event);
}

/**
* @generated
*/
protected IFigure createFigure() {
// Parent should assign one using setLabel() method
return null;
}

}

--------------080806040207050609020106--
Re: WrappingLabel multiline when editing [message #492719 is a reply to message #484177] Wed, 21 October 2009 13:57 Go to previous message
Francisco Javier Cano is currently offline Francisco Javier CanoFriend
Messages: 21
Registered: July 2009
Junior Member
Thanks, that is what I needed! :)

Alex Shatalin wrote:
> Hello Marc,
>
> See
> http://www.eclipse.org/newsportal/article.php?id=18921&g roup=eclipse.modeling.gmf
>
>
> -----------------
> Alex Shatalin
>
>
Previous Topic:Show validation error in GMF Application
Next Topic:Editing diagram programatically
Goto Forum:
  


Current Time: Sat Apr 20 11:47:33 GMT 2024

Powered by FUDForum. Page generated in 0.03824 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top