Java tutorial
/* * The DecidR Development Team licenses this file to you under * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package de.decidr.workflowmodeleditor.client.menu; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Window; import de.decidr.modelingtoolbase.client.command.ClearWorkflowCanvasCommand; import de.decidr.modelingtoolbase.client.command.CreateStartEndNodeCommand; import de.decidr.modelingtoolbase.client.exception.IncompleteModelDataException; import de.decidr.modelingtoolbase.client.model.IdGenerator; import de.decidr.modelingtoolbase.client.model.nodes.EndNodeModel; import de.decidr.modelingtoolbase.client.model.nodes.StartNodeModel; import de.decidr.workflowmodeleditor.client.WorkflowEditorWidget; /** * This command clears the workflow from all nodes and container and only leaves * a start and end node. * * @author Johannes Engelhardt * @author Daniel Willig */ public class ClearWorkflowMenuItem extends AbstractMenuItem implements Command { /** * Creates a new ClearWorkflowMenuItem. * * @param widget * The widget that owns this menu item. */ public ClearWorkflowMenuItem(WorkflowEditorWidget widget) { super(); setWidget(widget); } @Override public void execute() { if (Window.confirm(WorkflowEditorWidget.getMessages().confirmClearWorkflow())) { new ClearWorkflowCanvasCommand(getWidget().getWorkflowCanvas()).execute(); try { /* * Add start & end nodes. */ EndNodeModel endNodeModel = new EndNodeModel(getWidget().getWorkflowCanvas().getModel()); endNodeModel.setName(EndNodeModel.class.getName()); endNodeModel.setId(IdGenerator.generateId()); endNodeModel.setChangeListenerPosition(80, 100); StartNodeModel startNodeModel = new StartNodeModel(getWidget().getWorkflowCanvas().getModel()); startNodeModel.setName(StartNodeModel.class.getName()); startNodeModel.setId(IdGenerator.generateId()); startNodeModel.setChangeListenerPosition(10, 10); new CreateStartEndNodeCommand(endNodeModel, getWidget().getWorkflowCanvas()).execute(); new CreateStartEndNodeCommand(startNodeModel, getWidget().getWorkflowCanvas()).execute(); } catch (IncompleteModelDataException e) { // not expected to happen throw new RuntimeException(e); } } } }