Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Warning when editing label
Warning when editing label [message #178879] Tue, 25 March 2008 09:12 Go to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi,

I would like to add a warning if a certain attribute (label) in my diagram
is changed. My idea is to let pop up a MessageDialog as soon as the user
hits the "enter" key.
With the debuger I tried to find out in which command I can open the
MessageDialog but I didn't find a promising solution.

Any ideas?

Thanks for your help.
Marsha
Re: Warning when editing label [message #178907 is a reply to message #178879] Tue, 25 March 2008 15:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: 5d5.mail.ru

Have a look at IParser interface.

Marsha wrote:
> Hi,
>
> I would like to add a warning if a certain attribute (label) in my
> diagram is changed. My idea is to let pop up a MessageDialog as soon as
> the user hits the "enter" key.
> With the debuger I tried to find out in which command I can open the
> MessageDialog but I didn't find a promising solution.
>
> Any ideas?
>
> Thanks for your help.
> Marsha
>
Re: Warning when editing label [message #179047 is a reply to message #178907] Wed, 26 March 2008 08:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Dmitry,

Thank you for your hint. I had a look at that interface, but I don't
really see yet how I can use it for my purposes.

Can you give me some more hints?

Thank you,
Marsha
Re: Warning when editing label [message #180731 is a reply to message #179047] Thu, 03 April 2008 12:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Anyone else may help?

Thanks,
Marsha
Re: Warning when editing label [message #180830 is a reply to message #180731] Fri, 04 April 2008 03:04 Go to previous messageGo to next message
Lazar Codrut-Lucian is currently offline Lazar Codrut-LucianFriend
Messages: 91
Registered: July 2009
Member
I'm a novice here, but I'm working with the labels, so here is what I
think about this:

Look at the xxx.diagram.parsers package. You can create an IParser
starting from AbstractParser and MessageFormatParser.
AbstractParser has a protected ICommand getModificationCommand(..)
method which uses a standard SetValueCommand, so you can change this
with a different command.

Also, the xxx.diagram.edit.parts package contains the edit parts.
Suppose the label you want to check is Topic, the edit part will be
TopicEditPart and this one will contain an IParser field used in public
ICellEditorValidator getEditTextValidator() method. You can do other
things there, if needed (I suppose in that new
RunnableWithResult.Impl().run() method).

Hope this helps,
Lucian
Re: Warning when editing label [message #180857 is a reply to message #180830] Fri, 04 April 2008 08:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Lucian,

Thank you for your help.

> Look at the xxx.diagram.parsers package. You can create an IParser
> starting from AbstractParser and MessageFormatParser.
> AbstractParser has a protected ICommand getModificationCommand(..)
> method which uses a standard SetValueCommand, so you can change this
> with a different command.
I'll try this out, maybe it is possible to let the dialog pop up before
the getModificationCommand is called.

> Also, the xxx.diagram.edit.parts package contains the edit parts.
> Suppose the label you want to check is Topic, the edit part will be
> TopicEditPart and this one will contain an IParser field used in public
> ICellEditorValidator getEditTextValidator() method. You can do other
> things there, if needed (I suppose in that new
> RunnableWithResult.Impl().run() method).
I had a look at this too...my problem was that I didn't find out how to
invoke this method.

Greets,
Marsha
Re: Warning when editing label [message #181036 is a reply to message #180857] Sat, 05 April 2008 11:19 Go to previous messageGo to next message
Lazar Codrut-Lucian is currently offline Lazar Codrut-LucianFriend
Messages: 91
Registered: July 2009
Member
> I had a look at this too...my problem was that I didn't find out how to
> invoke this method.

That run() method is invoked automatically. You need to insert your code
in there, before
"setResult(parser.isValidEditString(new EObjectAdapter(element),
(String) value));"

You may observe that the EditPart implements ITextAwareEditPart. Only in
those methods you may add your custom code.

The problem is that the run() method is invoked every time you alter the
text in the editing label, not only when you press Enter.

This means that you need to catch the closing event of the
DirectEditManager, maybe by extending the TextDirectEditManager.
Re: Warning when editing label [message #181188 is a reply to message #180857] Mon, 07 April 2008 14:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

>> I had a look at this too...my problem was that I didn't find out how to
>> invoke this method.


> That run() method is invoked automatically. You need to insert your code
> in there, before
> "setResult(parser.isValidEditString(new EObjectAdapter(element),
> (String) value));"

> You may observe that the EditPart implements ITextAwareEditPart. Only in
> those methods you may add your custom code.

> The problem is that the run() method is invoked every time you alter the
> text in the editing label, not only when you press Enter.

> This means that you need to catch the closing event of the
> DirectEditManager, maybe by extending the TextDirectEditManager.

Thank you! I managed to do by customizing the getModificationCommand as
follows:

protected ICommand getModificationCommand(EObject element,
EAttribute feature, Object value) {
value = getValidNewValue(feature, value);
if (value instanceof InvalidValue) {
return UnexecutableCommand.INSTANCE;
}
//customization
if(!feature.getName().equals(value)){
MessageDialog.openWarning(Display.getCurrent().getActiveShel l(), "Step
name changed", "Here comes the warning");
}
//customization end
SetRequest request = new SetRequest(element, feature, value);
return new SetValueCommand(request);
}

Nevertheless this only works if I change the label in the diagram
directly. I'd like this dialog to appear as well if the name is changed
using the properties view.

Do you have an idea for this as well?

Thanks,
Marsha
Re: Warning when editing label [message #181404 is a reply to message #181188] Tue, 08 April 2008 11:50 Go to previous messageGo to next message
Lazar Codrut-Lucian is currently offline Lazar Codrut-LucianFriend
Messages: 91
Registered: July 2009
Member
Try adding an event listener to diagram.sheet.XxxSheetLabelProvider.
Or maybe intervene in XxxPropertySection.setInput method.

The properties panel is fully automated, so it's hard to track down the
place where you can plug your code in.
Re: Warning when editing label [message #181559 is a reply to message #181188] Tue, 08 April 2008 22:34 Go to previous messageGo to next message
Lazar Codrut-Lucian is currently offline Lazar Codrut-LucianFriend
Messages: 91
Registered: July 2009
Member
See the .edit project, and open the Provider for your element. You
should replace the ItemPropertyDescriptor that is created by default for
your property with a new one that overrides this method "public void
setPropertyValue(Object object, Object value)".

Lucian
Re: Warning when editing label [message #181591 is a reply to message #181559] Wed, 09 April 2008 11:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

> See the .edit project, and open the Provider for your element. You
> should replace the ItemPropertyDescriptor that is created by default for
> your property with a new one that overrides this method "public void
> setPropertyValue(Object object, Object value)".

> Lucian

Hi Lucian

Thank you for your help! This seams to work. But there is still a little
problem remaining.

I did the following. I subclassed ItemPropertyDescriptor like this:

public class CustomizedItemPropertyDescriptor extends
ItemPropertyDescriptor {

public CustomizedItemPropertyDescriptor(AdapterFactory adapterFactory,
ResourceLocator resourceLocator, String displayName,
String description, EStructuralFeature feature, boolean isSettable,
boolean multiLine, boolean sortChoices, Object staticImage,
String category, String[] filterFlags) {
super(adapterFactory, resourceLocator, displayName, description, feature,
isSettable, multiLine, sortChoices, staticImage, category,
filterFlags);
// TODO Auto-generated constructor stub
}

@Override
public void setPropertyValue(Object object, Object value) {
if(object instanceof Step){
if(!((Step) object).getName().equals(value))
MessageDialog.openWarning(Display.getCurrent().getActiveShel l(), "Step
name changed", "Here comes the warning");
//else name didn't change -> do nothing
}
super.setPropertyValue(object, value);
}
}

In my XXXItemProvider I return my CustomizedItemPropertyDescriptor for the
needed property:

protected void addNamePropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(new CustomizedItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
getResourceLocator(),
getString("_UI_Step_name_feature"),
getString("_UI_PropertyDescriptor_description",
"_UI_Step_name_feature", "_UI_Step_type"),
GamePackage.Literals.STEP__NAME,
true,
false,
false,
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
null,
null));
}

My problem is now that an IllegalStateException is thrown since
DefaultOperationHistory.openOperation() is called twice I think, when the
dialog is opened. Nevertheless the MessageDialog pops up and the value is
changed.

Can you tell me what I'm doing wrong?

Greets,
Marsha
Re: Warning when editing label [message #182011 is a reply to message #181591] Wed, 09 April 2008 17:15 Go to previous messageGo to next message
Lazar Codrut-Lucian is currently offline Lazar Codrut-LucianFriend
Messages: 91
Registered: July 2009
Member
I tested this and it works fine for me.
You need to debug it.
A stack trace would help.

Lucian
Re: Warning when editing label [message #182034 is a reply to message #182011] Thu, 10 April 2008 07:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Lucian,

Stange...

In debug mode I see that some how two different TriggeredOperations for
"Change Name Property" are sent. For the first everything works fine and
as soon as the second enters DefaultOperationHistory.openOperation() I get
the stack trace bellow:

org.eclipse.core.commands.ExecutionException: While executing the
operation, an exception occurred
at
org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:519)
at
org.eclipse.gmf.runtime.emf.ui.properties.sections.UndoableM odelPropertySheetEntry.valueChanged(UndoableModelPropertyShe etEntry.java:244)
at
org.eclipse.gmf.runtime.emf.ui.properties.sections.UndoableM odelPropertySheetEntry.setValue(UndoableModelPropertySheetEn try.java:199)
at
org.eclipse.gmf.runtime.emf.ui.properties.sections.UndoableM odelPropertySheetEntry.applyEditorValue(UndoableModelPropert ySheetEntry.java:127)
at org.eclipse.jface.viewers.CellEditor$1.run(CellEditor.java:3 05)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:857)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:46)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:19 9)
at
org.eclipse.jface.viewers.CellEditor.fireApplyEditorValue(Ce llEditor.java:303)
at org.eclipse.jface.viewers.CellEditor.focusLost(CellEditor.ja va:683)
at
org.eclipse.jface.viewers.TextCellEditor$5.focusLost(TextCel lEditor.java:185)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:136)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:962)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:943)
at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java: 2352)
at org.eclipse.swt.widgets.Widget.wmKillFocus(Widget.java:1681)
at org.eclipse.swt.widgets.Control.WM_KILLFOCUS(Control.java:40 00)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:3703 )
at org.eclipse.swt.widgets.Text.windowProc(Text.java:2013)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4364 )
at org.eclipse.swt.internal.win32.OS.BringWindowToTop(Native Method)
at org.eclipse.swt.widgets.Decorations.bringToTop(Decorations.j ava:227)
at org.eclipse.swt.widgets.Shell.open(Shell.java:1068)
at org.eclipse.jface.window.Window.open(Window.java:792)
at
org.eclipse.jface.dialogs.MessageDialog.openWarning(MessageD ialog.java:394)
at
game.provider.CustomizedItemPropertyDescriptor.setPropertyVa lue(CustomizedItemPropertyDescriptor.java:29)
at
org.eclipse.emf.edit.ui.provider.PropertySource.setPropertyV alue(PropertySource.java:116)
at
org.eclipse.gmf.runtime.emf.ui.properties.commands.SetModelP ropertyValueCommand.doExecuteWithResult(SetModelPropertyValu eCommand.java:104)
at
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTr ansactionalCommand.doExecute(AbstractTransactionalCommand.ja va:246)
at
org.eclipse.emf.workspace.AbstractEMFOperation.execute(Abstr actEMFOperation.java:137)
at
org.eclipse.emf.workspace.CompositeEMFOperation.doExecute(Co mpositeEMFOperation.java:212)
at
org.eclipse.emf.workspace.AbstractEMFOperation.execute(Abstr actEMFOperation.java:137)
at
org.eclipse.core.commands.operations.TriggeredOperations.exe cute(TriggeredOperations.java:165)
at
org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:511)
at
org.eclipse.gmf.runtime.emf.ui.properties.sections.UndoableM odelPropertySheetEntry.valueChanged(UndoableModelPropertyShe etEntry.java:244)
at
org.eclipse.gmf.runtime.emf.ui.properties.sections.UndoableM odelPropertySheetEntry.setValue(UndoableModelPropertySheetEn try.java:199)
at
org.eclipse.gmf.runtime.emf.ui.properties.sections.UndoableM odelPropertySheetEntry.applyEditorValue(UndoableModelPropert ySheetEntry.java:127)
at org.eclipse.jface.viewers.CellEditor$1.run(CellEditor.java:3 05)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:857)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:46)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:19 9)
at
org.eclipse.jface.viewers.CellEditor.fireApplyEditorValue(Ce llEditor.java:303)
at
org.eclipse.jface.viewers.TextCellEditor.handleDefaultSelect ion(TextCellEditor.java:294)
at
org.eclipse.jface.viewers.TextCellEditor$1.widgetDefaultSele cted(TextCellEditor.java:147)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:112)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3293)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 19)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:289)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:106)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:169)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 508)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
at org.eclipse.equinox.launcher.Main.main(Main.java:1148)
Caused by: java.lang.IllegalStateException: Cannot open an operation while
one is already open
at
org.eclipse.core.commands.operations.DefaultOperationHistory .openOperation(DefaultOperationHistory.java:1310)
at
org.eclipse.core.commands.operations.TriggeredOperations.exe cute(TriggeredOperations.java:163)
at
org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:511)
... 73 more
Re: Warning when editing label [message #182362 is a reply to message #182034] Fri, 11 April 2008 00:13 Go to previous messageGo to next message
Lazar Codrut-Lucian is currently offline Lazar Codrut-LucianFriend
Messages: 91
Registered: July 2009
Member
I cannot say what the problem is. I can only speculate.
It's clear that the same command is invoked twice, and the second time
is invoked before the first one finishes.
Try altering the setting for a different property. Maybe the fact that
you intervened in 2 places causes this conflict. The command is probably
triggered from different places.

Try leaving only the code in the CustomizedItemPropertyDescriptor, and
remove the code in the getModificationCommand(EObject).

Lucian
Re: Warning when editing label [message #183064 is a reply to message #182362] Tue, 15 April 2008 12:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Lucian,

I tried to only include the CustomizedItemPropertyDescriptor in a little
test project where this is the only customization. And I'm still having
the same problem. With the debugger I found out the the problem comes
somewhere from the org.eclipse.swt.internal.win32.OS.BringWindowToTop.

If I remember you told me that my solution is working for you? What are
you using? Maybe it is a problem of the platform?

Thank you for your help.
Marsha
Re: Warning when editing label [message #183521 is a reply to message #183064] Thu, 17 April 2008 21:43 Go to previous messageGo to next message
Lazar Codrut-Lucian is currently offline Lazar Codrut-LucianFriend
Messages: 91
Registered: July 2009
Member
I have linux (OpenSuse 10.2).
I don't know how to help you here.
Just catch the exception and ignore it.

Lucian
Re: Warning when editing label [solved] [message #185569 is a reply to message #181591] Tue, 06 May 2008 09:08 Go to previous message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi,

I managed to get an answer to my problem on the emf forum:
http://www.eclipse.org/newsportal/article.php?id=31883&g roup=eclipse.tools.emf#31883

My code looks now as follows:

public class StepNameItemPropertyDescriptor extends ItemPropertyDescriptor
{

public StepNameItemPropertyDescriptor(AdapterFactory adapterFactory,
ResourceLocator resourceLocator, String displayName,
String description, EStructuralFeature feature, boolean isSettable,
boolean multiLine, boolean sortChoices, Object staticImage,
String category, String[] filterFlags) {
super(adapterFactory, resourceLocator, displayName, description, feature,
isSettable, multiLine, sortChoices, staticImage, category,
filterFlags);
}

@Override
/**
* Returns true if the property was not already set.
*/
public boolean canSetProperty(Object object) {
if(object instanceof Step){
Step step = (Step) object;
//the step name was not set yet so it may be set
if(step.getName() == null || step.getName().equals("")){
return super.canSetProperty(object);
}
}
//if the step name was set once it can't be changed anymore
return false;
}

@Override
/**
* A Dialog is shown to inform the user why the property can be set only
once and is not editable.
*/
public String getDescription(Object object) {
if(object instanceof Step){
Step step = (Step) object;
//if the step name was already set show a warning dialog to inform the
user that step names can't be edited
if(step.getName() != null){
if(!step.getName().equals("")){
MessageDialog.openWarning(Display.getCurrent().getActiveShel l(), "Do
not rename Step Names", "Warning msg");
}
}
}
//if the step name was not set yet no dialog is needed
return super.getDescription(object);
}
}

Greets,
Marsha
Previous Topic:Palette's Position
Next Topic:G?F evaluation - general advice wanted
Goto Forum:
  


Current Time: Fri Apr 26 04:57:50 GMT 2024

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

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

Back to the top