| /******************************************************************************* |
| * Copyright (c) 2013 RCP Vision (http://www.rcp-vision.com) and others. |
| * 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: |
| * Francesco Guidieri - Initial contribution and API |
| *******************************************************************************/ |
| package org.eclipse.emf.parsley.views; |
| |
| |
| import org.eclipse.emf.common.command.Command; |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.emf.ecore.resource.Resource; |
| import org.eclipse.emf.parsley.builders.TableViewerBuilder; |
| import org.eclipse.emf.parsley.resource.ResourceLoader; |
| import org.eclipse.jface.viewers.TableViewer; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.widgets.Composite; |
| |
| import com.google.inject.Inject; |
| |
| public abstract class AbstractSaveableTableView extends AbstractSaveableViewerView { |
| |
| @Inject |
| protected TableViewerBuilder tableViewerBuilder; |
| |
| @Inject |
| protected ResourceLoader resourceLoader; |
| |
| protected TableViewer tableViewer; |
| |
| @Override |
| public void createPartControl(Composite parent) { |
| super.createPartControl(parent); |
| |
| tableViewer = new TableViewer(parent, createTableStyles()); |
| |
| tableViewerBuilder.buildAndFill(tableViewer, |
| getContents(getResource()), getEClass()); |
| |
| addContextMenu(tableViewer); |
| |
| getSite().setSelectionProvider(tableViewer); |
| } |
| |
| protected int createTableStyles() { |
| return SWT.BORDER | SWT.FULL_SELECTION; |
| } |
| |
| /** |
| * @param resource |
| * @return the contents from the passed resource to be shown in the table |
| */ |
| protected abstract Object getContents(Resource resource); |
| |
| /** |
| * @return the {@link EClass} for objects to be shown in the table |
| */ |
| protected abstract EClass getEClass(); |
| |
| @Override |
| public void setFocus() { |
| tableViewer.getTable().setFocus(); |
| } |
| |
| public TableViewer getViewer() { |
| return tableViewer; |
| } |
| |
| @Override |
| protected void mostRecentCommandAffectsResource(Command mostRecentCommand) { |
| super.mostRecentCommandAffectsResource(mostRecentCommand); |
| // for TableViewer the refresh does not seem to be automatic |
| tableViewer.refresh(); |
| } |
| } |