Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Graphical Modeling Framework/Tips"
(→Remove Property Sheet altogether) |
(→Remove Property Sheet altogether: highlighted changes with 'new' image) |
||
Line 66: | Line 66: | ||
</pre> | </pre> | ||
− | = Remove Property Sheet altogether = | + | = [[Image:New-small.gif]] Remove Property Sheet altogether = |
− | Add next method to the generated diagram editor class (usually <ModelName>DiagramEditor) | + | [[Image:New-small.gif]] Add next method to the generated diagram editor class (usually <ModelName>DiagramEditor) |
<pre> | <pre> |
Revision as of 17:18, 15 September 2006
I find those tips useful:
Contents
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); } } });
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); }