| /* |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| * Loetz GmbH&Co.KG |
| * |
| */ |
| package org.eclipse.osbp.vaadin.emf.views; |
| |
| import java.util.EventObject; |
| import java.util.List; |
| |
| import org.eclipse.emf.common.command.Command; |
| import org.eclipse.emf.common.command.CommandStackListener; |
| import org.eclipse.osbp.vaadin.emf.api.IModelingContext; |
| |
| import com.vaadin.data.Item; |
| import com.vaadin.ui.CustomComponent; |
| import com.vaadin.ui.Panel; |
| import com.vaadin.ui.Table; |
| import com.vaadin.ui.VerticalLayout; |
| |
| // TODO: Auto-generated Javadoc |
| /** |
| * The Class EmfCommandStackTableViewer. |
| */ |
| @SuppressWarnings({ "serial", "restriction" }) |
| public class EmfCommandStackTableViewer extends CustomComponent implements |
| CommandStackListener { |
| |
| /** The Constant EVENT_TYPE_NAME. */ |
| public static final String EVENT_TYPE_NAME = "eventType"; |
| |
| /** The table. */ |
| private Table table; |
| |
| /** The modeling context. */ |
| private IModelingContext modelingContext; |
| |
| /** |
| * Instantiates a new emf command stack table viewer. |
| * |
| * @param modelingContext |
| * the modeling context |
| */ |
| public EmfCommandStackTableViewer(IModelingContext modelingContext) { |
| this.modelingContext = modelingContext; |
| |
| modelingContext.getCommandStack().addCommandStackListener(this); |
| |
| Panel mainLayout = new Panel(); |
| mainLayout.setSizeFull(); |
| setCompositionRoot(mainLayout); |
| |
| VerticalLayout scrollArea = new VerticalLayout(); |
| scrollArea.setMargin(true); |
| mainLayout.setContent(scrollArea); |
| |
| table = new Table(); |
| table.setSizeFull(); |
| scrollArea.addComponent(table); |
| |
| table.addContainerProperty("name", String.class, ""); |
| // table.addContainerProperty("can undo", CheckBox.class, ""); |
| // table.addContainerProperty("can redo", CheckBox.class, ""); |
| |
| fillTable(); |
| |
| table.setItemCaptionPropertyId("name"); |
| } |
| |
| /** |
| * Fill table. |
| */ |
| @SuppressWarnings("unchecked") |
| private void fillTable() { |
| table.removeAllItems(); |
| |
| List<Command> commands = modelingContext.getCommandStack() |
| .getAllCommands(); |
| for (int i = commands.size() - 1; i >= 0; i--) { |
| Item item = table.addItem(commands.get(i)); |
| item.getItemProperty("name").setValue(commands.get(i).getLabel()); |
| } |
| |
| table.select(modelingContext.getCommandStack().getMostRecentCommand()); |
| table.setValue(modelingContext.getCommandStack().getMostRecentCommand()); |
| } |
| |
| /** |
| * Is required to be called. |
| */ |
| public void dispose() { |
| table = null; |
| modelingContext.getCommandStack().removeCommandStackListener(this); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.emf.common.command.CommandStackListener#commandStackChanged(java.util.EventObject) |
| */ |
| @Override |
| public void commandStackChanged(EventObject event) { |
| fillTable(); |
| } |
| |
| } |