public void run() { // Fetch viewer from editor part (might not work, if not, try some other way) EditPartViewer viewer = (EditPartViewer) part.getAdapter(EditPartViewer.class); // get Target EditPart that is under the mouse EditPart targetEditPart = viewer.findObjectAt(getLocation()); // If nothing under mouse, set root item as target (just playing safe) if(targetEditPart == null) targetEditPart = viewer.getContents(); // Make and initialize create request with proper information CreateRequest createReq = new CreateRequest(); createReq.setLocation(getLocation()); createReq.setFactory(new OwnFactoryImplementation()); // Ask from target editpart command for this request Command command = targetEditPart.getCommand(createReq); // If command is ok, and it can be executed, go and execute it on commandstack if(command != null && command.canExecute()) { viewer.getEditDomain().getCommandStack().execute(command); } }
@Override public void visit(CreateRequest request) { coapRequest = Request.newPost(); coapRequest.getOptions().setContentFormat(request.getContentFormat().getCode()); // if no instance id, the client will assign it. int instanceId = request.getInstanceId() != null ? request.getInstanceId() : LwM2mObjectInstance.UNDEFINED; coapRequest.setPayload(encoder.encode(new LwM2mObjectInstance(instanceId, request.getResources()), request.getContentFormat(), request.getPath(), model)); setTarget(coapRequest, request.getPath()); }
@Override public void visit(CreateRequest request) { coapRequest = Request.newPost(); coapRequest.getOptions().setContentFormat(request.getContentFormat().getCode()); coapRequest.setPayload(LwM2mNodeEncoder.encode(request.getObjectInstance(), request.getContentFormat(), request.getPath())); setTarget(coapRequest, destination, request.getPath()); }
@Override public void visit(CreateRequest request) { o.add("kind", "create"); o.add("contentFormat", request.getContentFormat().getCode()); if (request.getInstanceId() != null) o.add("instanceId", request.getInstanceId()); JsonArray resources = new JsonArray(); for (LwM2mResource resource : request.getResources()) { resources.add(LwM2mNodeSerDes.jSerialize(resource)); } o.add("resources", resources); }
CreateRequest request = new CreateRequest(contentFormat, target, (LwM2mObjectInstance) node); CreateResponse cResponse = server.send(registration, request, TIMEOUT); processDeviceResponse(req, resp, cResponse);
@Override protected CreateResponse doCreate(CreateRequest request) { Integer instanceId = request.getInstanceId(); if (instanceId == null) { // the client is in charge to generate the id of the new instance if (instances.isEmpty()) { instanceId = 0; } else { instanceId = Collections.max(instances.keySet()) + 1; } } LwM2mInstanceEnabler newInstance = instanceFactory.create(getObjectModel()); for (LwM2mResource resource : request.getResources()) { newInstance.write(resource.getId(), resource); } instances.put(instanceId, newInstance); listenInstance(newInstance, instanceId); return CreateResponse.success(new LwM2mPath(request.getPath().getObjectId(), instanceId).toString()); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("CreateRequest [").append(getPath()).append("]"); return builder.toString(); }
@Override public void visit(CreateRequest request) { o.add("kind", "create"); o.add("contentFormat", request.getContentFormat().getCode()); if (request.getInstanceId() != null) o.add("instanceId", request.getInstanceId()); JsonArray resources = new JsonArray(); for (LwM2mResource resource : request.getResources()) { resources.add(LwM2mNodeSerDes.jSerialize(resource)); } o.add("resources", resources); }
LwM2mInstanceEnabler instanceEnabler = instances.get(instanceNode.getId()); if (instanceEnabler == null) { doCreate(new CreateRequest(path.getObjectId(), instanceNode)); } else { doWrite(identity, new WriteRequest(Mode.REPLACE, path.getObjectId(), path.getObjectInstanceId(), LwM2mInstanceEnabler instanceEnabler = instances.get(path.getObjectInstanceId()); if (instanceEnabler == null) { doCreate(new CreateRequest(path.getObjectId(), instanceNode)); } else { doWrite(identity, new WriteRequest(Mode.REPLACE, request.getContentFormat(), path.getObjectId(), LwM2mInstanceEnabler instanceEnabler = instances.get(path.getObjectInstanceId()); if (instanceEnabler == null) { doCreate(new CreateRequest(path.getObjectId(), new LwM2mObjectInstance(path.getObjectInstanceId(), resource))); } else {
resources.add(resource); return new CreateRequest(ContentFormat.fromCode(format), path, new LwM2mObjectInstance(instanceId, resources));
resources.add(resource); return new CreateRequest(ContentFormat.fromCode(format), path, new LwM2mObjectInstance(instanceId, resources));
createRequest = new CreateRequest(contentFormat, path.getObjectId(), newInstance); } else { createRequest = new CreateRequest(contentFormat, path.getObjectId(), newInstance.getResources().values());