Java tutorial
/** * This file is part of the eConference project and it is distributed under the * terms of the MIT Open Source license. * * The MIT License * Copyright (c) 2005 Collaborative Development Group - Dipartimento di Informatica, * University of Bari, http://cdg.di.uniba.it * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be included in all copies * or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package it.uniba.di.cdg.econference.planningpoker.ui; import it.uniba.di.cdg.econference.planningpoker.model.backlog.DefaultUserStory; import it.uniba.di.cdg.econference.planningpoker.model.backlog.IBacklogViewUIProvider; import it.uniba.di.cdg.econference.planningpoker.utils.AutoResizeTableLayout; import org.eclipse.jface.viewers.CellLabelProvider; import org.eclipse.jface.viewers.ColumnPixelData; import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Table; public class DefaultBacklogViewUIProvider implements IBacklogViewUIProvider { @Override public Object[] getElements(Object inputElement) { return (Object[]) inputElement; } @Override public void dispose() { // TODO Auto-generated method stub } @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // TODO Auto-generated method stub } @Override public void createColumns(TableViewer viewer) { String[] titles = new String[] { "ID", "Story Text", "Milestone", "Estimate" }; int[] bounds = new int[] { 50, 320, 90, 70 }; for (int i = 0; i < titles.length; i++) { final int index = i; TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText(titles[i]); column.getColumn().setWidth(bounds[i]); column.getColumn().setResizable(true); column.getColumn().setMoveable(true); column.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { DefaultUserStory story = (DefaultUserStory) cell.getElement(); switch (index) { case 0: cell.setText(story.getId()); break; case 1: cell.setText(story.getStoryText()); break; case 2: cell.setText(story.getMilestoneName()); break; case 3: String estimate = story.getEstimate().toString(); if (estimate.isEmpty() || estimate.equals("0.0")) estimate = "?"; cell.setText(estimate); break; } } }); //column.setEditingSupport(new SimpleBacklogEditingSupport(viewer,i)); } AutoResizeTableLayout layout = new AutoResizeTableLayout(viewer.getTable()); layout.addColumnData(new ColumnPixelData(bounds[0])); layout.addColumnData(new ColumnWeightData(1)); layout.addColumnData(new ColumnPixelData(bounds[2])); layout.addColumnData(new ColumnPixelData(bounds[3])); Table table = viewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(false); } }