/* Licensed 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 org.activiti.editor.ui; import org.activiti.editor.constants.ModelDataJsonConstants; import org.activiti.engine.ProcessEngines; import org.activiti.engine.RepositoryService; import org.activiti.engine.repository.Model; import org.activiti.explorer.ExplorerApp; import org.activiti.explorer.I18nManager; import org.activiti.explorer.Messages; import org.activiti.explorer.ui.custom.PopupWindow; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.Reindeer; /** * @author Tijs Rademakers */ public class DeleteModelPopupWindow extends PopupWindow implements ModelDataJsonConstants { private static final long serialVersionUID = 1L; protected I18nManager i18nManager; protected VerticalLayout windowLayout; protected Model modelData; protected RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService(); public DeleteModelPopupWindow(Model model) { this.modelData = model; this.windowLayout = (VerticalLayout) getContent(); this.i18nManager = ExplorerApp.get().getI18nManager(); initWindow(); addDeleteWarning(); addButtons(); } protected void initWindow() { windowLayout.setSpacing(true); addStyleName(Reindeer.WINDOW_LIGHT); setModal(true); setWidth("300px"); center(); setCaption(i18nManager.getMessage(Messages.PROCESS_DELETE_POPUP_CAPTION, modelData.getName())); } protected void addDeleteWarning() { Label deleteLabel = new Label(i18nManager.getMessage(Messages.PROCESS_DELETE_POPUP_MESSAGE)); deleteLabel.addStyleName(Reindeer.LABEL_SMALL); addComponent(deleteLabel); // Some empty space Label emptySpace = new Label(" ", Label.CONTENT_XHTML); addComponent(emptySpace); } protected void addButtons() { // Cancel Button cancelButton = new Button(i18nManager.getMessage(Messages.BUTTON_CANCEL)); cancelButton.addStyleName(Reindeer.BUTTON_SMALL); cancelButton.addListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { close(); } }); // Convert Button deleteButton = new Button(i18nManager.getMessage(Messages.PROCESS_DELETE_POPUP_DELETE_BUTTON)); deleteButton.addStyleName(Reindeer.BUTTON_SMALL); deleteButton.addListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { repositoryService.deleteModel(modelData.getId()); close(); ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(); } }); // Alignment HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.addComponent(cancelButton); buttonLayout.addComponent(deleteButton); addComponent(buttonLayout); windowLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT); } }