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.
Tips for lames
Revision as of 09:24, 14 June 2006 by Unnamed Poltroon (Talk)
I'm lame GMF user and 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("Tworzenie dziesięciu modułów"); for (int i=0; i<1; i++) { cmd.add(modulesCompartment.getCommand(req)); } selectedElement.getDiagramEditDomain().getDiagramCommandStack().execute(cmd); 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 EtoolsProxyCommand(operation)); } } }
more will be soon.