Skip to content

Commit

Permalink
Merge pull request #138 from eclipse/issues_137
Browse files Browse the repository at this point in the history
Issues 137
  • Loading branch information
gerring authored Jun 14, 2017
2 parents eacc2c9 + a13e1da commit aa38a65
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public interface IBeanController<T> {
*/
T getBean();

/**
* Calling this method assigns the linked bean to some other data
* and it calls a beanToUI() to update the UI.
* @param model
* @throws Exception from the beanToUI() if the bean cannot update the UI
*/
T setBean(T model) throws Exception;

/**
* Returns the original UI object to which we are linking with reflection.
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class BeanController<T> implements IBeanController<T> {

private final Object ui;
private final T bean;
private T bean;

/**
* Create a new BeanController with the given UI and bean objects. Note the
Expand All @@ -61,6 +61,12 @@ public T getBean() {
return bean;
}

public T setBean(T bean) throws Exception {
T old = this.bean;
this.bean = bean;
beanToUI();
return old;
}
/**
* Send the bean values to the UI
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*-
* Copyright (c) 2012 Diamond Light Source Ltd.
*
* 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
*/
package org.eclipse.richbeans.widgets.table;

import java.util.function.Predicate;

/**
*
* A view whose main contant is a SeriesTable may optionally implement this
* interface. This allows other views to interact with the items in the view.
*
* It is something of a back door and should be used with caution. Instead
* normal RCP selection events should be used to communicate between views
* or a proper controller pattern. However in the cases where a series view
* should be searched for and changed, this interface can be used to avoid
* depending on the concrete part.
*
* @author Matthew Gerring
*
*/
public interface SeriesItemView {

/**
* Test if the items in the series table
* @param class1
* @return
*/
<T> boolean isSeriesOf(Class<T> class1);

/**
* Searchs for the first ISeriesItemDescriptor matching the defined predicate.
* @param predicate
* @return
*/
ISeriesItemDescriptor find(Predicate<ISeriesItemDescriptor> predicate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.bindings.keys.IKeyLookup;
Expand Down Expand Up @@ -260,11 +261,21 @@ public void setLockEditing(boolean checked) {
}

public List<ISeriesItemDescriptor> getSeriesItems() {
if (tableViewer==null) return null;
if (tableViewer==null) return Collections.emptyList();
SeriesContentProvider prov = (SeriesContentProvider)tableViewer.getContentProvider();
return prov.getSeriesItems();
}

/**
* Searchs for a matching ISeriesItemDescriptor in the list of descriptors
* @param predicate
* @return
*/
public ISeriesItemDescriptor find(Predicate<ISeriesItemDescriptor> predicate) {
if (tableViewer==null) return null;
return getSeriesItems().stream().filter(predicate::test).findFirst().orElse(null);
}

/**
* Add a new operation to the list.
*/
Expand Down

0 comments on commit aa38a65

Please sign in to comment.