Skip to content

Commit

Permalink
trying to catch update events from the filter table...
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhofer committed May 11, 2010
1 parent b79173b commit ea9309e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ object ClassFilterTable {
}

class ClassFilterTable(parent: Composite) {
def build = {
private var listener: FilterChangeListener = null

def withChangeListener(listener: FilterChangeListener) = {
this.listener = listener
this
}

def build() = {
val classFilterTable = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION)

configureTable(classFilterTable)
Expand All @@ -54,15 +61,15 @@ class ClassFilterTable(parent: Composite) {
.titled("Kind").notMoveable
.withLayout(tableLayout).withWeightAndMinimumSize(0, 100)
.build
.setEditingSupport(
ClassFilterTableEditingSupport.forViewerAndColumn(classFilterTable, 0))
.setEditingSupport(ClassFilterTableEditingSupport.forViewerAndColumn(classFilterTable, 0))

TableColumnBuilder.forTableViewer(classFilterTable).aligned(SWT.LEFT)
.titled("Type Pattern").notMoveable
.withLayout(tableLayout).withWeightAndMinimumSize(100, 200)
.build
.setEditingSupport(
ClassFilterTableEditingSupport.forViewerAndColumn(classFilterTable, 1))
.setEditingSupport(ClassFilterTableEditingSupport
.forViewerAndColumn(classFilterTable, 1)
.withChangeListener(listener))

classFilterTable.getTable.setLayout(tableLayout)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,26 @@ import org.eclipse.jface.viewers._
import ecobertura.core.data.filters._

object ClassFilterTableEditingSupport {
def forViewerAndColumn(viewer: ColumnViewer, column: Int) =
def forViewerAndColumn(viewer: TableViewer, column: Int) =
new ClassFilterTableEditingSupport(viewer, column)
}

class ClassFilterTableEditingSupport(viewer: ColumnViewer, column: Int)
class ClassFilterTableEditingSupport(viewer: TableViewer, column: Int)
extends EditingSupport(viewer) {

private var listener: Option[FilterChangeListener] = None

val swtTable = viewer.asInstanceOf[TableViewer].getTable
val cellEditor = column match {
case 0 => new ComboBoxCellEditor(swtTable, Array("include", "exclude"))
case 1 => new TextCellEditor(swtTable)
}

def withChangeListener(listener: FilterChangeListener) = {
this.listener = Some(listener)
this
}

override def getValue(element: Any) : Object = {
val classFilter = element.asInstanceOf[ClassFilter]
column match {
Expand All @@ -52,6 +59,10 @@ class ClassFilterTableEditingSupport(viewer: ColumnViewer, column: Int)
case 1 => filterToUpdate.pattern = value.asInstanceOf[String]
}
getViewer.update(element, null)
listener match {
case Some(listener) => listener.filtersChanged(viewer)
case None => /* nothing to do */
}
}

override def canEdit(element: Any) = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package ecobertura.ui.launching.config.filters
import org.eclipse.swt.SWT
import org.eclipse.swt.layout._
import org.eclipse.swt.widgets.{Composite, Label}
import org.eclipse.jface.viewers.TableViewer

import org.eclipse.debug.ui.AbstractLaunchConfigurationTab
import org.eclipse.debug.core._
Expand All @@ -30,11 +31,12 @@ import ecobertura.core.data.filters._

// TODO call setDirty and updateConfigurationDialog when changes are being made...

class CoverageConfigurationFilterTab extends AbstractLaunchConfigurationTab {
class CoverageConfigurationFilterTab extends AbstractLaunchConfigurationTab
with FilterChangeListener {

override def getName = "Filters"

override def performApply(workingCopyOfLaunchConfiguration: ILaunchConfigurationWorkingCopy) = {
//import scala.collection.JavaConversions._
// TODO
}

Expand Down Expand Up @@ -80,5 +82,11 @@ class CoverageConfigurationFilterTab extends AbstractLaunchConfigurationTab {
}

private def addIncludeExcludeClassesGroupTo(panel: Composite) =
IncludeExcludeClassesGroupBuilder.forParent(panel).build
IncludeExcludeClassesGroupBuilder.forParent(panel).withChangeListener(this).build()

override def filtersChanged(viewer: TableViewer) = {
println("filters changed")
setDirty(true)
updateLaunchConfigurationDialog()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file is part of eCobertura.
*
* Copyright (c) 2010 Joachim Hofer
* All rights reserved.
*
* eCobertura is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* eCobertura is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with eCobertura. If not, see <http://www.gnu.org/licenses/>.
*/
package ecobertura.ui.launching.config.filters

import org.eclipse.jface.viewers.TableViewer

trait FilterChangeListener {
def filtersChanged(viewer: TableViewer)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package ecobertura.ui.launching.config.filters

import org.eclipse.swt.SWT
import org.eclipse.swt.events.SelectionEvent
import org.eclipse.swt.widgets._
import org.eclipse.swt.layout._
import org.eclipse.jface.viewers._
Expand All @@ -37,16 +38,22 @@ class IncludeExcludeClassesGroupBuilder(parent: Composite) {
private var includeExcludeGroup: Group = null
private var includeExcludeTable: TableViewer = null
private var tableHolder: Composite = null
private var listener: FilterChangeListener = null

def build = {
includeExcludeGroup = initializeIncludeExcludeGroup
def withChangeListener(listener: FilterChangeListener) = {
this.listener = listener
this
}

def build() = {
includeExcludeGroup = initializeIncludeExcludeGroup()
buildBasicIncludeExcludeGroupLayout(includeExcludeGroup)
tableHolder = initializeIncludeExcludeTableHolder(includeExcludeGroup)
includeExcludeTable = initializeIncludeExcludeTableIn(tableHolder)
initializeButtons
includeExcludeTable = initializeIncludeExcludeTable(tableHolder, listener)
initializeButtons()
}

private def initializeIncludeExcludeGroup = {
private def initializeIncludeExcludeGroup() = {
val includeExcludeGroup = new Group(parent, SWT.NONE)
includeExcludeGroup.setText("Classes to Include/Exclude:")
includeExcludeGroup.setLayout(new FormLayout)
Expand All @@ -71,24 +78,24 @@ class IncludeExcludeClassesGroupBuilder(parent: Composite) {
tableHolder
}

private def initializeIncludeExcludeTableIn(parent: Composite) =
ClassFilterTable.forParent(parent).build
private def initializeIncludeExcludeTable(parent: Composite, listener: FilterChangeListener) =
ClassFilterTable.forParent(parent).withChangeListener(listener).build()

private def initializeButtons = {
private def initializeButtons() = {
val addIncludeButton = initializeAddIncludeButton
val addExcludeButton = initializeAddExcludeButton(addIncludeButton)
val removeButton = initializeRemoveButton(addExcludeButton)
}

private def initializeAddIncludeButton = {
private def initializeAddIncludeButton() = {
val addIncludeButton = new Button(includeExcludeGroup, SWT.PUSH)
addIncludeButton.setText("Add Include Filter")
FormDataBuilder.forFormElement(addIncludeButton)
.topAtPercent(0, 5).rightNeighborOf(tableHolder, 5).rightAtPercent(100, 5)
.build
addIncludeButton.addSelectionListener {
addIncludeButton.addSelectionListener((event: SelectionEvent) => {
addAndEditClassFilterPattern(ClassFilter(IncludeFilter, "*"))
}
})
addIncludeButton
}

Expand All @@ -98,15 +105,16 @@ class IncludeExcludeClassesGroupBuilder(parent: Composite) {
FormDataBuilder.forFormElement(addExcludeButton)
.bottomNeighborOf(addIncludeButton, 5).rightNeighborOf(tableHolder, 5)
.rightAtPercent(100, 5).build
addExcludeButton.addSelectionListener {
addExcludeButton.addSelectionListener((event: SelectionEvent) => {
addAndEditClassFilterPattern(ClassFilter(ExcludeFilter, "*"))
}
})
addExcludeButton
}

private def addAndEditClassFilterPattern(classFilter: ClassFilter) = {
includeExcludeTable.add(classFilter)
includeExcludeTable.editElement(classFilter, 1)
listener.filtersChanged(includeExcludeTable)
}

private def initializeRemoveButton(addExcludeButton: Control) = {
Expand All @@ -115,10 +123,11 @@ class IncludeExcludeClassesGroupBuilder(parent: Composite) {
FormDataBuilder.forFormElement(removeButton)
.bottomNeighborOf(addExcludeButton, 15).rightNeighborOf(tableHolder, 5)
.rightAtPercent(100, 5).build
removeButton.addSelectionListener {
removeButton.addSelectionListener((event: SelectionEvent) => {
val swtTable = includeExcludeTable.getTable
swtTable.remove(swtTable.getSelectionIndex)
}
listener.filtersChanged(includeExcludeTable)
})
removeButton
}
}
4 changes: 2 additions & 2 deletions ecobertura.ui/src/main/scala/ecobertura/ui/util/Predef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ object Predef {
override def run = func
}

implicit def selectionListener(func: => Unit): SelectionListener = new SelectionAdapter {
override def widgetSelected(event: SelectionEvent) = func
implicit def selectionListener(func: SelectionEvent => Unit): SelectionListener = new SelectionAdapter {
override def widgetSelected(event: SelectionEvent) = func(event)
}

implicit def selectionChangedListener(func: SelectionChangedEvent => Unit) = new ISelectionChangedListener {
Expand Down

0 comments on commit ea9309e

Please sign in to comment.