Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Persisting non-model properties/preferences
Persisting non-model properties/preferences [message #88951] Tue, 02 January 2007 18:14 Go to next message
Eclipse UserFriend
Originally posted by: rbbnjmn.yahoo.com

Our diagram editor will allow users to specify graphical preferences.
For example, we may provide for a choice of several connection
anchoring algorythms. These would be on a per-diagram basis.

Since these are non-model properties I want to persist them in the
diagram file only.

Is there a supported GMF mechanism to support this?

Thanks

Roy
Re: Persisting non-model properties/preferences [message #89139 is a reply to message #88951] Wed, 03 January 2007 07:29 Go to previous messageGo to next message
Eclipse UserFriend
Hello rbbnjmn,

Each org.eclipse.gmf.runtime.notation.View (Diagram is a subclass on View)
can has several Styles attached. You can create your own style by creating
..ecore model with CustomStyle class extending Style defined in notation model
and then attach this style to your instance of Diagram. As a result you’ll
get typed storage for all the properties (in CustomStyle you can create all
necessary attributes to store desired properties).

-----------------
Alex Shatalin
Re: Persisting non-model properties/preferences [message #89258 is a reply to message #89139] Wed, 03 January 2007 20:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rbbnjmn.yahoo.com

Alex,

Thanks for the info.

As usual, I have a few questions....

What I have done is start with an empty .ecore model, then added an eClass
"CustomStyle" with one attr, an EBoolean. The ESuper type is Style, another
eClass I added where I specified the instance class to be
org.eclipse.runtime.notation.Style
and Interface=true. Generated necessary code, and ran.

As a test I added the following lines to
xxxxEditorUtil.createNewDiagramFile:

Style s =
diagram.createStyle(com.vitria.modeling.custom.custom.Custom Package.eINSTANCE.getCustomStyle());
System.out.println("\n\ns:"+s+"\n\n");

All seems Ok, no exceptions and the print out is fine.

1) Do I need to do something more to 'attach' this style to my diagram?
2) Assuming the style has been attached, will the property appear in the
diagram's property sheet dynamically? (Its not, so this may just be
wishful
thinking.)

Thanks!

Roy

"Alex Shatalin" <vano@borland.com> wrote in message
news:3c3172e6e9e48c8fd525bb4a404@news.eclipse.org...
> Hello rbbnjmn,
>
> Each org.eclipse.gmf.runtime.notation.View (Diagram is a subclass on View)
> can has several Styles attached. You can create your own style by creating
> .ecore model with CustomStyle class extending Style defined in notation
> model and then attach this style to your instance of Diagram. As a result
> you'll get typed storage for all the properties (in CustomStyle you can
> create all necessary attributes to store desired properties).
>
> -----------------
> Alex Shatalin
>
>
>
Re: Persisting non-model properties/preferences [message #89319 is a reply to message #89258] Thu, 04 January 2007 04:45 Go to previous messageGo to next message
Eclipse UserFriend
I've done something similar and I think I needed to add two other
things (I've included code examples that you may or may not find
useful):

1) Add the custom style to the relevant views in the view factory. In
my case, the custom style was only relevant for one model class, to
only one of the generated view factories needed change.

public class ComputationViewFactory extends AbstractShapeViewFactory {

/**
* @NOT generated
*/
protected List createStyles(View view) {
List styles = new ArrayList();

styles.add(NotationFactory.eINSTANCE.createFontStyle());

styles.add(NotationFactory.eINSTANCE.createDescriptionStyle( ));

styles.add(NotationFactory.eINSTANCE.createFillStyle());

styles.add(NotationFactory.eINSTANCE.createLineStyle());
// added support for direction style

styles.add(no.hal.diamodl.notation.NotationFactory.eINSTANCE
.createDirectionStyle());
return styles;
}

2) I needed to add a section to the appearance property section. This
requires creating a new property section, a property section filter
and declaring it in plugin.xml:

<extension
point="org.eclipse.ui.views.properties.tabbed.propertySections ">
<propertySections contributorId="no.hal.diamodl.gmf.diagram">

<propertySection
id="property.section.ConnectorAppearancePropertySection"

filter=" no.hal.diamodl.diagram.custom.sheet.ComputationEditPartPrope rtySectionFilter "

class=" no.hal.diamodl.diagram.custom.sheet.ComputationAppearancePro pertySection "
tab="property.tab.AppearancePropertySection">
</propertySection>

</propertySections>
</extension>

public class ComputationEditPartPropertySectionFilter
implements IFilter {

public boolean select(Object object) {
if (object instanceof AbstractComputationEditPart && (!
(object instanceof AbstractGateEditPart))) {
return true;
}
return false;
}
}

public class ComputationAppearancePropertySection extends
AbstractNotationPropertiesSection {

// Controls
private CCombo directionCombo;
private CLabel directionLabel;

/**
* @see
org.eclipse.gmf.runtime.common.ui.properties.view.ITabbedPro pertySection#refresh()
*/
public void refresh() {
try {
executeAsReadAction(new Runnable() {
public void run() {
// Update display from model
if (getSingleInput()
instanceof AbstractComputationEditPart) {

AbstractComputationEditPart comp = (AbstractComputationEditPart)
getSingleInput();
DirectionStyle
direction = (DirectionStyle)comp.getNotationView().getStyle(

NotationPackage.eINSTANCE.getDirectionStyle());

directionCombo.select(directionConstants.indexOf(direction.g etDirection()));
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* @see
org.eclipse.gmf.runtime.common.ui.properties.ISection#create Controls(org.eclipse.swt.widgets.Composite,
*
org.eclipse.gmf.runtime.common.ui.properties.TabbedPropertyS heetPage)
*/
public void createControls(Composite parent,
TabbedPropertySheetPage
aTabbedPropertySheetPage) {
super.createControls(parent,
aTabbedPropertySheetPage);

FormData data;

// Create checkbox
directionCombo =
getWidgetFactory().createCCombo(composite);
data = new FormData();
data.left = new FormAttachment(0,
getStandardLabelWidth(parent));
data.top = new FormAttachment(0, 0);
directionCombo.setLayoutData(data);
String[] items = ...
directionCombo.setItems(items);
directionCombo.addSelectionListener(new
SelectionAdapter() {

public void widgetSelected(SelectionEvent
event) {
if (isReadOnly()) {
refresh();
return;
}
ArrayList commands = new ArrayList();
for (Iterator it =
getInput().iterator(); it.hasNext();) {
EditPart ep =
(EditPart)it.next();
int selection =
directionCombo.getSelectionIndex();
if (selection < 0) {
selection = 0;
}
if (ep instanceof
AbstractComputationEditPart) {
DirectionConstants
direction = getDirectionConstant(selection);
commands.add(new
CommandProxy(ChangeComputationDirectionEditPolicy.getChangeD irectionStyleCommand(ep,
direction)));
}
}
executeAsCompositeCommand("Change
direction", commands);
}
});
directionLabel =
getWidgetFactory().createCLabel(composite, "Direction");
data = new FormData();
data.left = new FormAttachment(0, 0);
data.top = new FormAttachment(directionCombo, 0,
SWT.CENTER);
directionLabel.setLayoutData(data);
}
}



On Wed, 3 Jan 2007 17:15:55 -0800, "rbbnjmn" <rbbnjmn@yahoo.com>
wrote:

>Alex,
>
>Thanks for the info.
>
>As usual, I have a few questions....
>
>What I have done is start with an empty .ecore model, then added an eClass
>"CustomStyle" with one attr, an EBoolean. The ESuper type is Style, another
>eClass I added where I specified the instance class to be
>org.eclipse.runtime.notation.Style
>and Interface=true. Generated necessary code, and ran.
>
>As a test I added the following lines to
>xxxxEditorUtil.createNewDiagramFile:
>
> Style s =
> diagram.createStyle(com.vitria.modeling.custom.custom.Custom Package.eINSTANCE.getCustomStyle());
> System.out.println("\n\ns:"+s+"\n\n");
>
>All seems Ok, no exceptions and the print out is fine.
>
>1) Do I need to do something more to 'attach' this style to my diagram?
>2) Assuming the style has been attached, will the property appear in the
> diagram's property sheet dynamically? (Its not, so this may just be
>wishful
> thinking.)
>
>Thanks!
>
>Roy
>
>"Alex Shatalin" <vano@borland.com> wrote in message
>news:3c3172e6e9e48c8fd525bb4a404@news.eclipse.org...
>> Hello rbbnjmn,
>>
>> Each org.eclipse.gmf.runtime.notation.View (Diagram is a subclass on View)
>> can has several Styles attached. You can create your own style by creating
>> .ecore model with CustomStyle class extending Style defined in notation
>> model and then attach this style to your instance of Diagram. As a result
>> you'll get typed storage for all the properties (in CustomStyle you can
>> create all necessary attributes to store desired properties).
>>
>> -----------------
>> Alex Shatalin
>>
>>
>>
>
Re: Persisting non-model properties/preferences [message #89380 is a reply to message #89258] Thu, 04 January 2007 08:12 Go to previous messageGo to next message
Eclipse UserFriend
Hello rbbnjmn,

> "CustomStyle" with one attr, an EBoolean. The ESuper type is Style,
> another eClass I added where I specified the instance class to be
> org.eclipse.runtime.notation.Style and Interface=true.
I think you can just load notation model into your .ecore file editor using
popup menu item and then you'll be able to set superclass property to the
"Style" EClass defined in the notation model.

> 1) Do I need to do something more to 'attach' this style to my
> diagram?
I think not - you should have CustomStyle attached (and saved into the diagram
file!) already.

> 2) Assuming the style has been attached, will the property appear in
> the diagram's property sheet dynamically? (Its not, so this may just
Not sure about that. I suppose, not. Looks like you have to create your own
property support for it - nobody knows hows to represent CustomStyle in properties
view...

-----------------
Alex Shatalin
Re: Persisting non-model properties/preferences [message #89763 is a reply to message #89380] Fri, 05 January 2007 13:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rbbnjmn.yahoo.com

Thanks Alex,

Very useful!

Roy

"Alex Shatalin" <vano@borland.com> wrote in message
news:3c3172e6ea7b8c8fe2170a4fe0d@news.eclipse.org...
> Hello rbbnjmn,
>
>> "CustomStyle" with one attr, an EBoolean. The ESuper type is Style,
>> another eClass I added where I specified the instance class to be
>> org.eclipse.runtime.notation.Style and Interface=true.
> I think you can just load notation model into your .ecore file editor
> using popup menu item and then you'll be able to set superclass property
> to the "Style" EClass defined in the notation model.
>
>> 1) Do I need to do something more to 'attach' this style to my
>> diagram?
> I think not - you should have CustomStyle attached (and saved into the
> diagram file!) already.
>
>> 2) Assuming the style has been attached, will the property appear in
>> the diagram's property sheet dynamically? (Its not, so this may just
> Not sure about that. I suppose, not. Looks like you have to create your
> own property support for it - nobody knows hows to represent CustomStyle
> in properties view...
>
> -----------------
> Alex Shatalin
>
>
Re: Persisting non-model properties/preferences [message #91359 is a reply to message #89319] Wed, 10 January 2007 16:14 Go to previous message
Eclipse UserFriend
Originally posted by: rbbnjmn.yahoo.com

Hallvard,

I think I have followed your example, and so now have everything working
except one
thing.

Something is being initialized when I create a new diagram that is not
initialized when
I open an existing one. So I get a stack trace (included here). If I
create a new diagram
before opening an existing one, then I have no problems. Did you also see
this and if
so how did you correct it?

The problem occurs in the FileInfo createFileInfo(..) call in the
IntegrationDocumentProvider.
This generated code adds a modification listener whose super^ class calls:
editingDomain = TransactionUtil.getEditingDomain(diagram);
which returns null, therebye the NPE.

Thanks!

Roy

java.lang.NullPointerException
at
org.eclipse.emf.transaction.util.TransactionUtil.getEditingD omain(TransactionUtil.java:50)
at
org.eclipse.gmf.runtime.diagram.ui.resources.editor.document .DiagramModificationListener. <init>(DiagramModificationListener.java:55)
at
org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.docu ment.FileDiagramModificationListener. <init>(FileDiagramModificationListener.java:54)
at
com.vvv.modeling.core.integration.diagram.part.IntegrationDo cumentProvider$CustomModificationListener. <init>(IntegrationDocumentProvider.java:216)
at
com.vvv.modeling.core.integration.diagram.part.IntegrationDo cumentProvider.createFileInfo(IntegrationDocumentProvider.ja va:158)
at
org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.docu ment.FileDocumentProvider.createElementInfo(FileDocumentProv ider.java:486)
at
org.eclipse.gmf.runtime.diagram.ui.resources.editor.document .AbstractDocumentProvider.connect(AbstractDocumentProvider.j ava:387)
at
org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.Di agramDocumentEditor.doSetInput(DiagramDocumentEditor.java:42 6)
at
org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.Di agramDocumentEditor.setInput(DiagramDocumentEditor.java:389)
at
org.eclipse.gef.ui.parts.GraphicalEditor.init(GraphicalEdito r.java:318)
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.init( DiagramEditor.java:638)
at
org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.Di agramDocumentEditor.init(DiagramDocumentEditor.java:116)
at
org.eclipse.ui.internal.EditorManager.createSite(EditorManag er.java:839)
at
org.eclipse.ui.internal.EditorReference.createPartHelper(Edi torReference.java:583)
at
org.eclipse.ui.internal.EditorReference.createPart(EditorRef erence.java:372)
at
org.eclipse.ui.internal.WorkbenchPartReference.getPart(Workb enchPartReference.java:566)
at
org.eclipse.ui.internal.EditorAreaHelper.setVisibleEditor(Ed itorAreaHelper.java:263)
at
org.eclipse.ui.internal.EditorManager.setVisibleEditor(Edito rManager.java:1420)
at
org.eclipse.ui.internal.EditorManager$5.run(EditorManager.ja va:1005)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:843)
at
org.eclipse.ui.internal.EditorManager.restoreState(EditorMan ager.java:1000)
at
org.eclipse.ui.internal.WorkbenchPage.restoreState(Workbench Page.java:2836)
at
org.eclipse.ui.internal.WorkbenchWindow.restoreState(Workben chWindow.java:1936)
at
org.eclipse.ui.internal.Workbench.doRestoreState(Workbench.j ava:2857)
at org.eclipse.ui.internal.Workbench.access$14(Workbench.java:2 805)
at org.eclipse.ui.internal.Workbench$19.run(Workbench.java:1681 )
at
org.eclipse.ui.internal.Workbench.runStartupWithProgress(Wor kbench.java:1421)
at
org.eclipse.ui.internal.Workbench.restoreState(Workbench.jav a:1679)
at org.eclipse.ui.internal.Workbench.access$12(Workbench.java:1 650)
at org.eclipse.ui.internal.Workbench$17.run(Workbench.java:1529 )
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at
org.eclipse.ui.internal.Workbench.restoreState(Workbench.jav a:1473)
at
org.eclipse.ui.internal.WorkbenchConfigurer.restoreState(Wor kbenchConfigurer.java:183)
at
org.eclipse.ui.application.WorkbenchAdvisor.openWindows(Work benchAdvisor.java:702)
at org.eclipse.ui.internal.Workbench.init(Workbench.java:1085)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1847)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
at
org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplicatio n.java:95)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)

"Hallvard Tr
Previous Topic:Get an instance
Next Topic:Switching Diagram Tabs causes ToolBar flicker
Goto Forum:
  


Current Time: Fri May 09 00:10:00 EDT 2025

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

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

Back to the top