Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Graphical Modeling Framework/Tips

< Graphical Modeling Framework
Revision as of 10:01, 26 October 2006 by Alexander.shatalin.borland.com (Talk | contribs) (Image:New-small.gif Remove Property Sheet altogether)

I find those tips useful:

Creating New Elements And Corresponding Views

DeviceEditPart selectedElement = ...;

String compartemntsSemanticHint = NetworkVisualIDRegistry.getType(tests.mindmap.network.diagram.edit.parts.Device_ModulesCompartmentEditPart.VISUAL_ID);
Device_ModulesCompartmentEditPart modulesCompartment = (Device_ModulesCompartmentEditPart)selectedElement.getChildBySemanticHint(compartemntsSemanticHint);

IElementType type = NetworkElementTypes.Module_3001;

ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
		new CreateElementRequestAdapter(new CreateElementRequest(type)),
		Node.class,
		((IHintedType) type).getSemanticHint(), 
		selectedElement.getDiagramPreferencesHint());

CreateViewAndElementRequest req = new CreateViewAndElementRequest(viewDescriptor);
CompoundCommand cmd = new CompoundCommand("Create 10 modules");
for (int i=0; i<10; i++) {
	cmd.add(modulesCompartment.getCommand(req));
}
selectedElement.getDiagramEditDomain().getDiagramCommandStack().execute(cmd);

Change Names Of Newly Created Elements

Collection results = DiagramCommandStack.getReturnValues(cmd);
for (Object res: results) {
	if (res instanceof IAdaptable) {
		IAdaptable adapter = (IAdaptable) res;
		View view = (View) adapter.getAdapter(View.class);
		if (view != null) {
			Module newMod = (Module)view.getElement();
			SetRequest reqSet = new SetRequest(selectedElement.getEditingDomain(),
					newMod, NetworkPackage.eINSTANCE.getNamedElement_Name(),
					"ModX");
			SetValueCommand operation = new SetValueCommand(reqSet);
			selectedElement.getDiagramEditDomain().getDiagramCommandStack().execute(new 
					ICommandProxy(operation));
		}
	}
}

Create New Elements Using RecordingCommand and CanonicalEditPolicies


final Device dev = (Device)((View)selectedElement.getModel()).getElement();
TransactionalEditingDomain editingDomain = selectedElement.getEditingDomain();
editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
	@SuppressWarnings("unchecked")
	protected void doExecute() {
		dev.setName("Morda13");
		for (int i = 0; i < 5; i++) {
			Module newMod = NetworkFactory.eINSTANCE.createModule();
			newMod.setName("X26 - " + i);
			dev.getModules().add(newMod);
		}
	}
});

New-small.gif Remove Property Sheet altogether

Add next method to the generated diagram editor class (usually <ModelName>DiagramEditor)

	public Object getAdapter(Class type) {
		if (type == IPropertySheetPage.class) {
			return null;
		}
		return super.getAdapter(type);
	}

New-small.gif Using the same instance of editing in several generated diagrams

Back to the top