Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 215134 Details for
Bug 378003
[activity] integrate a TableViewer in the Task Editor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Code for the viewer
TaskEditorActivityPart.java (text/plain), 9.30 KB, created by
Timur Achmetow
on 2012-05-05 16:15:27 EDT
(
hide
)
Description:
Code for the viewer
Filename:
MIME Type:
Creator:
Timur Achmetow
Created:
2012-05-05 16:15:27 EDT
Size:
9.30 KB
patch
obsolete
>/******************************************************************************* > * Copyright (c) 2012 Timur Achmetow 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: > * Timur Achmetow - initial API and implementation > *******************************************************************************/ > >package org.eclipse.mylyn.internal.tasks.ui.editors; > >import java.util.ArrayList; >import java.util.List; > >import org.eclipse.jface.viewers.ArrayContentProvider; >import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; >import org.eclipse.jface.viewers.ITableLabelProvider; >import org.eclipse.jface.viewers.LabelProvider; >import org.eclipse.jface.viewers.TableViewer; >import org.eclipse.jface.viewers.TableViewerColumn; >import org.eclipse.jface.viewers.Viewer; >import org.eclipse.jface.viewers.ViewerComparator; >import org.eclipse.jface.window.ToolTip; >import org.eclipse.mylyn.commons.core.CoreUtil; >import org.eclipse.mylyn.commons.ui.TableSorter; >import org.eclipse.mylyn.tasks.core.data.TaskDataModel; >import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; >import org.eclipse.swt.SWT; >import org.eclipse.swt.events.SelectionAdapter; >import org.eclipse.swt.events.SelectionEvent; >import org.eclipse.swt.graphics.Image; >import org.eclipse.swt.layout.GridData; >import org.eclipse.swt.widgets.Button; >import org.eclipse.swt.widgets.Composite; >import org.eclipse.swt.widgets.Table; >import org.eclipse.swt.widgets.TableColumn; >import org.eclipse.ui.forms.widgets.FormToolkit; >import org.eclipse.ui.forms.widgets.Section; > >/** > * @author Timur Achmetow > */ >public class TaskEditorActivityPart extends AbstractTaskEditorPart { > > public TaskEditorActivityPart() { > setPartName("Task Activity"); //$NON-NLS-1$ > } > > @Override > public void createControl(Composite parent, final FormToolkit toolkit) { > > final Section section = createSection(parent, toolkit, true); > section.setText("Task Activity Tracing"); //$NON-NLS-1$ > > Composite activityComposite = toolkit.createComposite(section); > activityComposite.setLayout(EditorUtil.createSectionClientLayout()); > activityComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); > > createTableViewer(toolkit, activityComposite); > > section.setClient(activityComposite); > setSection(toolkit, section); > } > > private void createTableViewer(final FormToolkit toolkit, Composite parent) { > > TableViewer viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION > | SWT.BORDER); > viewer.setUseHashlookup(true); > ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE); > final Table table = viewer.getTable(); > > table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); > table.setHeaderVisible(true); > table.setLinesVisible(true); > > createTableViewerColumn(viewer, "Author", 120, 0); //$NON-NLS-1$ > TableViewerColumn dateCol = createTableViewerColumn(viewer, "Date", 120, 1); //$NON-NLS-1$ > table.setSortColumn(dateCol.getColumn()); > table.setSortDirection(SWT.DOWN); > createTableViewerColumn(viewer, "Files", 300, 2); //$NON-NLS-1$ > createTableViewerColumn(viewer, "Message", 400, 3); //$NON-NLS-1$ > > viewer.setSorter(new ActivityTableSorter()); > viewer.setContentProvider(new ArrayContentProvider()); > viewer.setLabelProvider(new ActivityLabelProvider()); > viewer.setInput(getDummyModel()); > > Button button = toolkit.createButton(parent, "Testing", SWT.PUSH); > button.addSelectionListener(new SelectionAdapter() { > @Override > public void widgetSelected(SelectionEvent event) { > > TaskDataModel model = getModel(); > System.out.println("Task data:"); > System.out.println(model.getTask().getTaskId()); > System.out.println(model.getTask().getSummary()); > System.out.println(model.getTask().getUrl()); > System.out.println("Repo data:"); > System.out.println(model.getTaskRepository().getUrl()); > System.out.println(model.getTaskRepository().getUserName()); > > } > }); > } > > private TableViewerColumn createTableViewerColumn(TableViewer viewer, String title, int bound, int index) { > > final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); > final TableColumn column = viewerColumn.getColumn(); > column.setText(title); > column.setWidth(bound); > column.setResizable(true); > column.setMoveable(true); > column.addSelectionListener(getSelectionAdapter(column, viewer, index)); > return viewerColumn; > } > > private SelectionAdapter getSelectionAdapter(final TableColumn column, final TableViewer viewer, final int index) { > SelectionAdapter selectionAdapter = new SelectionAdapter() { > @Override > public void widgetSelected(SelectionEvent e) { > ActivityViewerComparator myViewerComparator = new ActivityViewerComparator(); > myViewerComparator.setColumn(index); > int dir = myViewerComparator.getDirection(); > viewer.getTable().setSortDirection(dir); > viewer.getTable().setSortColumn(column); > viewer.refresh(); > } > }; > return selectionAdapter; > } > > private class ActivityTableSorter extends TableSorter { > > @Override > public int compare(TableViewer viewer, Object e1, Object e2, int columnIndex) { > ActivityModel activity1 = (ActivityModel) e1; > ActivityModel activity2 = (ActivityModel) e2; > switch (columnIndex) { > case 0: > return CoreUtil.compare(activity1.getAutor(), activity2.getAutor()); > case 1: > return CoreUtil.compare(activity1.getDate(), activity2.getDate()); > case 2: > return CoreUtil.compare(activity1.getFiles(), activity2.getFiles()); > case 3: > return CoreUtil.compare(activity1.getMessage(), activity2.getMessage()); > } > return super.compare(viewer, e1, e2, columnIndex); > } > > } > > public class ActivityViewerComparator extends ViewerComparator { > private int propertyIndex; > > private static final int DESCENDING = 1; > > private int direction = DESCENDING; > > public ActivityViewerComparator() { > this.propertyIndex = 0; > direction = DESCENDING; > } > > public int getDirection() { > return direction == 1 ? SWT.DOWN : SWT.UP; > } > > public void setColumn(int column) { > if (column == this.propertyIndex) { > // Same column as last sort; toggle the direction > direction = 1 - direction; > } else { > // New column; do an ascending sort > this.propertyIndex = column; > direction = DESCENDING; > } > } > > @Override > public int compare(Viewer viewer, Object e1, Object e2) { > ActivityModel activity1 = (ActivityModel) e1; > ActivityModel activity2 = (ActivityModel) e2; > int rc = 0; > switch (propertyIndex) { > case 0: > rc = CoreUtil.compare(activity1.getAutor(), activity2.getAutor()); > break; > case 1: > rc = CoreUtil.compare(activity1.getDate(), activity2.getDate()); > break; > case 2: > rc = CoreUtil.compare(activity1.getFiles(), activity2.getFiles()); > break; > case 3: > rc = CoreUtil.compare(activity1.getMessage(), activity2.getMessage()); > break; > default: > rc = 0; > } > // If descending order, flip the direction > if (direction == DESCENDING) { > rc = -rc; > } > return rc; > } > > } > > private class ActivityLabelProvider extends LabelProvider implements ITableLabelProvider { > > public Image getColumnImage(Object element, int columnIndex) { > // not implemented > return null; > } > > public String getColumnText(Object element, int columnIndex) { > if (element instanceof ActivityModel) { > switch (columnIndex) { > case 0: > return ((ActivityModel) element).getAutor(); > case 1: > return ((ActivityModel) element).getDate(); > case 2: > return ((ActivityModel) element).getFiles(); > case 3: > return ((ActivityModel) element).getMessage(); > default: > throw new IllegalArgumentException("Column is not existing."); //$NON-NLS-1$ > } > } > return super.getText(element); > } > } > > private List<ActivityModel> getDummyModel() { > List<ActivityModel> dummyList = new ArrayList<ActivityModel>(); > dummyList.add(new ActivityModel("Steffen Pingel", "2011-08-17", "Hudson.java", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ > "open of task corresponding to change set fails for Git change sets")); //$NON-NLS-1$ > dummyList.add(new ActivityModel("Torkild Resheim", "2011-08-04", "HudsonDiscovery.java", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ > "Automatic discovery should distinguish between Jenkins")); //$NON-NLS-1$ > dummyList.add(new ActivityModel("Kevin Sawicki", "2011-08-09", "TestResultPart.java", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ > "[patch] add preference for showing test failures Only")); //$NON-NLS-1$ > dummyList.add(new ActivityModel("Lucas Panjer", "2012-04-04", "BuildsView.java", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ > "Automatically refresh the Builds view upon user initiated activation or bringing to foreground")); //$NON-NLS-1$ > return dummyList; > } > > private class ActivityModel { > private final String autor; > > private final String date; > > private final String files; > > private final String message; > > public ActivityModel(String string, String string2, String string3, String string4) { > autor = string; > date = string2; > files = string3; > message = string4; > } > > public String getAutor() { > return autor; > } > > public String getDate() { > return date; > } > > public String getFiles() { > return files; > } > > public String getMessage() { > return message; > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 378003
:
215033
|
215034
|
215132
|
215133
| 215134 |
216795