Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Riena » MasterDetailComposite
MasterDetailComposite [message #24995] Fri, 01 May 2009 20:00 Go to next message
gabe is currently offline gabeFriend
Messages: 7
Registered: July 2009
Junior Member
Can I customize MasterDetailComposite?
* Hide or remove "New", "Remove", and "Apply" buttons?
* Have master table updated as I type in the detail widgets (instead of
when "Apply" is clicked)?
Re: MasterDetailComposite [message #25239 is a reply to message #24995] Sun, 03 May 2009 21:50 Go to previous messageGo to next message
Christian Campo is currently offline Christian CampoFriend
Messages: 597
Registered: July 2009
Senior Member
gabe schrieb:
> Can I customize MasterDetailComposite?
> * Hide or remove "New", "Remove", and "Apply" buttons?
> * Have master table updated as I type in the detail widgets (instead of
> when "Apply" is clicked)?
>
MasterDetailComposite is relativly new. So there is currently no way to customize itself. You can subclass it and then
write your own widget (or at least the part that you like to be changed). This only requires you then to define a new
mapping between the widget to the original ridget. (http://wiki.eclipse.org/Riena_Custom_Ridgets)

And while you are add it, this can possibly mean that also need to subclass, rewrite the ridget code.

If you like to contribute or what to document your requirements in more detail, a bugzilla with that as a content is
always a good help. That is also a good place after a few discussion rounds to think about contributing a patch.

What we do have actually now that I think of it, is the option to have a different look for the buttons. If you look in
the example there under playground (subapplication) under playground (module) there is MasterDetail 2 (actually probably
not in 1.1.0.M6 but its in 1.1.0.M7 which we do next week or you can also checkout the sourcecode)

does that help ?

christian
Re: MasterDetailComposite [message #25323 is a reply to message #24995] Tue, 05 May 2009 06:46 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-dev.volanakis.de

This is a multi-part message in MIME format.
--------------080005050302080603070306
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hi Gabe,

> * Hide or remove "New", "Remove", and "Apply" buttons?

yes, that's easy:

IMasterDetailsRidget ridget;
ridget.getRidget(MasterDetailsComposite.BIND_ID_APPLY).setVi sible(false);
// see MasterDetailsComposite for other constants

> * Have master table updated as I type in the detail widgets (instead of
> when "Apply" is clicked)?

Theoretically yes - practically no. Two problems here:
(a) there is no official API;
(b) apply clears the details area

See the attached snippet for an example (not useful because of (b)).
Best open a bug with your requirements / use-case and we can continue
the discussion there.

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Riena

Kind regards,
Elias.


--------------080005050302080603070306
Content-Type: text/plain;
name="Snippet.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Snippet.java"

/*********************************************************** ********************
* Copyright (c) 2007, 2009 compeople AG 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:
* compeople AG - initial API and implementation
************************************************************ *******************/
package org.eclipse.riena.sample.snippets;

import java.beans.PropertyChangeListener;

import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import org.eclipse.riena.beans.common.Person;
import org.eclipse.riena.beans.common.PersonFactory;
import org.eclipse.riena.internal.ui.ridgets.swt.MasterDetailsRidge t;
import org.eclipse.riena.ui.core.marker.ValidationTime;
import org.eclipse.riena.ui.ridgets.IMasterDetailsDelegate;
import org.eclipse.riena.ui.ridgets.IMasterDetailsRidget;
import org.eclipse.riena.ui.ridgets.IRidget;
import org.eclipse.riena.ui.ridgets.IRidgetContainer;
import org.eclipse.riena.ui.ridgets.ITextRidget;
import org.eclipse.riena.ui.ridgets.swt.SwtRidgetFactory;
import org.eclipse.riena.ui.ridgets.validation.NotEmpty;
import org.eclipse.riena.ui.swt.MasterDetailsComposite;
import org.eclipse.riena.ui.swt.utils.UIControlsFactory;

/**
* A master details ridget. The master area shows a table of persons. The detail
* area can rename a person.
*/
public final class Snippet {

private Snippet() {
// "utility class"
}

/**
* A master details widget with a text fields for renaming a person.
*/
private static final class PersonMasterDetails extends MasterDetailsComposite {

PersonMasterDetails(Composite parent, int style) {
super(parent, style, SWT.BOTTOM);
}

@Override
protected void createDetails(Composite parent) {
GridLayoutFactory.fillDefaults().numColumns(2).margins(20, 20).spacing(10, 10).equalWidth(false).applyTo(
parent);
GridDataFactory hFill = GridDataFactory.fillDefaults().grab(true, false);

UIControlsFactory.createLabel(parent, "Last Name:"); //$NON-NLS-1$
Text txtLast = UIControlsFactory.createText(parent);
hFill.applyTo(txtLast);
addUIControl(txtLast, "txtLast"); //$NON-NLS-1$

UIControlsFactory.createLabel(parent, "First Name:"); //$NON-NLS-1$
Text txtFirst = UIControlsFactory.createText(parent);
hFill.applyTo(txtFirst);
addUIControl(txtFirst, "txtFirst"); //$NON-NLS-1$
}

@Override
protected int getDetailsStyle() {
return SWT.BORDER;
}
}

/**
* A IMasterDetailsDelegate that renames a person.
*/
private static final class PersonDelegate implements IMasterDetailsDelegate {

private final Person workingCopy = createWorkingCopy();

public void configureRidgets(final IRidgetContainer container) {
ITextRidget txtLast = (ITextRidget) container.getRidget("txtLast"); //$NON-NLS-1$
txtLast.bindToModel(workingCopy, Person.PROPERTY_LASTNAME);
txtLast.addValidationRule(new NotEmpty(), ValidationTime.ON_UI_CONTROL_EDIT);
txtLast.updateFromModel();

ITextRidget txtFirst = (ITextRidget) container.getRidget("txtFirst"); //$NON-NLS-1$
txtFirst.bindToModel(workingCopy, Person.PROPERTY_FIRSTNAME);
txtFirst.updateFromModel();

PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent event) {
System.out.println("pcl: " + event.getNewValue());
if (isValid(container) == null) {
// non API - use at own peril
// note that apply does deselect; so this is not very useful
((MasterDetailsRidget) container).handleApply();
}
}
};
txtLast.addPropertyChangeListener(ITextRidget.PROPERTY_TEXT, listener);
txtFirst.addPropertyChangeListener(ITextRidget.PROPERTY_TEXT , listener);
}

public Person copyBean(Object source, Object target) {
Person from = source != null ? (Person) source : createWorkingCopy();
Person to = target != null ? (Person) target : createWorkingCopy();
to.setFirstname(from.getFirstname());
to.setLastname(from.getLastname());
return to;
}

public Person createWorkingCopy() {
return new Person("", ""); //$NON-NLS-1$ //$NON-NLS-2$
}

public Person getWorkingCopy() {
return workingCopy;
}

public boolean isChanged(Object source, Object target) {
Person p1 = (Person) source;
Person p2 = (Person) target;
boolean equal = p1.getFirstname().equals(p2.getFirstname()) && p1.getLastname().equals(p2.getLastname());
return !equal;
}

public String isValid(IRidgetContainer container) {
ITextRidget txtLast = (ITextRidget) container.getRidget("txtLast"); //$NON-NLS-1$
if (txtLast.isErrorMarked()) {
return "'Last Name' is not valid."; //$NON-NLS-1$
}
return null;
}

public void updateDetails(IRidgetContainer container) {
for (IRidget ridget : container.getRidgets()) {
ridget.updateFromModel();
}
}
}

public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

PersonMasterDetails details = new PersonMasterDetails(shell, SWT.NONE);

IMasterDetailsRidget ridget = (IMasterDetailsRidget) SwtRidgetFactory.createRidget(details);
ridget.setDelegate(new PersonDelegate());
WritableList input = new WritableList(PersonFactory.createPersonList(), Person.class);
String[] properties = { Person.PROPERTY_LASTNAME, Person.PROPERTY_FIRSTNAME };
String[] headers = { "Last Name", "First Name" }; //$NON-NLS-1$ //$NON-NLS-2$
ridget.bindToModel(input, Person.class, properties, headers);
ridget.updateFromModel();

/*
* Hide the REMOVE and APPLY buttons
*/
ridget.getRidget(MasterDetailsComposite.BIND_ID_REMOVE).setV isible(false);
ridget.getRidget(MasterDetailsComposite.BIND_ID_APPLY).setVi sible(false);

shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

display.dispose();
}
}

--------------080005050302080603070306--
Re: MasterDetailComposite [message #582155 is a reply to message #24995] Sun, 03 May 2009 21:50 Go to previous message
Christian Campo is currently offline Christian CampoFriend
Messages: 597
Registered: July 2009
Senior Member
gabe schrieb:
> Can I customize MasterDetailComposite?
> * Hide or remove "New", "Remove", and "Apply" buttons?
> * Have master table updated as I type in the detail widgets (instead of
> when "Apply" is clicked)?
>
MasterDetailComposite is relativly new. So there is currently no way to customize itself. You can subclass it and then
write your own widget (or at least the part that you like to be changed). This only requires you then to define a new
mapping between the widget to the original ridget. (http://wiki.eclipse.org/Riena_Custom_Ridgets)

And while you are add it, this can possibly mean that also need to subclass, rewrite the ridget code.

If you like to contribute or what to document your requirements in more detail, a bugzilla with that as a content is
always a good help. That is also a good place after a few discussion rounds to think about contributing a patch.

What we do have actually now that I think of it, is the option to have a different look for the buttons. If you look in
the example there under playground (subapplication) under playground (module) there is MasterDetail 2 (actually probably
not in 1.1.0.M6 but its in 1.1.0.M7 which we do next week or you can also checkout the sourcecode)

does that help ?

christian
Re: MasterDetailComposite [message #582188 is a reply to message #24995] Tue, 05 May 2009 06:46 Go to previous message
Elias Volanakis is currently offline Elias VolanakisFriend
Messages: 43
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------080005050302080603070306
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hi Gabe,

> * Hide or remove "New", "Remove", and "Apply" buttons?

yes, that's easy:

IMasterDetailsRidget ridget;
ridget.getRidget(MasterDetailsComposite.BIND_ID_APPLY).setVi sible(false);
// see MasterDetailsComposite for other constants

> * Have master table updated as I type in the detail widgets (instead of
> when "Apply" is clicked)?

Theoretically yes - practically no. Two problems here:
(a) there is no official API;
(b) apply clears the details area

See the attached snippet for an example (not useful because of (b)).
Best open a bug with your requirements / use-case and we can continue
the discussion there.

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Riena

Kind regards,
Elias.


--------------080005050302080603070306
Content-Type: text/plain;
name="Snippet.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Snippet.java"

/*********************************************************** ********************
* Copyright (c) 2007, 2009 compeople AG 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:
* compeople AG - initial API and implementation
************************************************************ *******************/
package org.eclipse.riena.sample.snippets;

import java.beans.PropertyChangeListener;

import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import org.eclipse.riena.beans.common.Person;
import org.eclipse.riena.beans.common.PersonFactory;
import org.eclipse.riena.internal.ui.ridgets.swt.MasterDetailsRidge t;
import org.eclipse.riena.ui.core.marker.ValidationTime;
import org.eclipse.riena.ui.ridgets.IMasterDetailsDelegate;
import org.eclipse.riena.ui.ridgets.IMasterDetailsRidget;
import org.eclipse.riena.ui.ridgets.IRidget;
import org.eclipse.riena.ui.ridgets.IRidgetContainer;
import org.eclipse.riena.ui.ridgets.ITextRidget;
import org.eclipse.riena.ui.ridgets.swt.SwtRidgetFactory;
import org.eclipse.riena.ui.ridgets.validation.NotEmpty;
import org.eclipse.riena.ui.swt.MasterDetailsComposite;
import org.eclipse.riena.ui.swt.utils.UIControlsFactory;

/**
* A master details ridget. The master area shows a table of persons. The detail
* area can rename a person.
*/
public final class Snippet {

private Snippet() {
// "utility class"
}

/**
* A master details widget with a text fields for renaming a person.
*/
private static final class PersonMasterDetails extends MasterDetailsComposite {

PersonMasterDetails(Composite parent, int style) {
super(parent, style, SWT.BOTTOM);
}

@Override
protected void createDetails(Composite parent) {
GridLayoutFactory.fillDefaults().numColumns(2).margins(20, 20).spacing(10, 10).equalWidth(false).applyTo(
parent);
GridDataFactory hFill = GridDataFactory.fillDefaults().grab(true, false);

UIControlsFactory.createLabel(parent, "Last Name:"); //$NON-NLS-1$
Text txtLast = UIControlsFactory.createText(parent);
hFill.applyTo(txtLast);
addUIControl(txtLast, "txtLast"); //$NON-NLS-1$

UIControlsFactory.createLabel(parent, "First Name:"); //$NON-NLS-1$
Text txtFirst = UIControlsFactory.createText(parent);
hFill.applyTo(txtFirst);
addUIControl(txtFirst, "txtFirst"); //$NON-NLS-1$
}

@Override
protected int getDetailsStyle() {
return SWT.BORDER;
}
}

/**
* A IMasterDetailsDelegate that renames a person.
*/
private static final class PersonDelegate implements IMasterDetailsDelegate {

private final Person workingCopy = createWorkingCopy();

public void configureRidgets(final IRidgetContainer container) {
ITextRidget txtLast = (ITextRidget) container.getRidget("txtLast"); //$NON-NLS-1$
txtLast.bindToModel(workingCopy, Person.PROPERTY_LASTNAME);
txtLast.addValidationRule(new NotEmpty(), ValidationTime.ON_UI_CONTROL_EDIT);
txtLast.updateFromModel();

ITextRidget txtFirst = (ITextRidget) container.getRidget("txtFirst"); //$NON-NLS-1$
txtFirst.bindToModel(workingCopy, Person.PROPERTY_FIRSTNAME);
txtFirst.updateFromModel();

PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent event) {
System.out.println("pcl: " + event.getNewValue());
if (isValid(container) == null) {
// non API - use at own peril
// note that apply does deselect; so this is not very useful
((MasterDetailsRidget) container).handleApply();
}
}
};
txtLast.addPropertyChangeListener(ITextRidget.PROPERTY_TEXT, listener);
txtFirst.addPropertyChangeListener(ITextRidget.PROPERTY_TEXT , listener);
}

public Person copyBean(Object source, Object target) {
Person from = source != null ? (Person) source : createWorkingCopy();
Person to = target != null ? (Person) target : createWorkingCopy();
to.setFirstname(from.getFirstname());
to.setLastname(from.getLastname());
return to;
}

public Person createWorkingCopy() {
return new Person("", ""); //$NON-NLS-1$ //$NON-NLS-2$
}

public Person getWorkingCopy() {
return workingCopy;
}

public boolean isChanged(Object source, Object target) {
Person p1 = (Person) source;
Person p2 = (Person) target;
boolean equal = p1.getFirstname().equals(p2.getFirstname()) && p1.getLastname().equals(p2.getLastname());
return !equal;
}

public String isValid(IRidgetContainer container) {
ITextRidget txtLast = (ITextRidget) container.getRidget("txtLast"); //$NON-NLS-1$
if (txtLast.isErrorMarked()) {
return "'Last Name' is not valid."; //$NON-NLS-1$
}
return null;
}

public void updateDetails(IRidgetContainer container) {
for (IRidget ridget : container.getRidgets()) {
ridget.updateFromModel();
}
}
}

public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

PersonMasterDetails details = new PersonMasterDetails(shell, SWT.NONE);

IMasterDetailsRidget ridget = (IMasterDetailsRidget) SwtRidgetFactory.createRidget(details);
ridget.setDelegate(new PersonDelegate());
WritableList input = new WritableList(PersonFactory.createPersonList(), Person.class);
String[] properties = { Person.PROPERTY_LASTNAME, Person.PROPERTY_FIRSTNAME };
String[] headers = { "Last Name", "First Name" }; //$NON-NLS-1$ //$NON-NLS-2$
ridget.bindToModel(input, Person.class, properties, headers);
ridget.updateFromModel();

/*
* Hide the REMOVE and APPLY buttons
*/
ridget.getRidget(MasterDetailsComposite.BIND_ID_REMOVE).setV isible(false);
ridget.getRidget(MasterDetailsComposite.BIND_ID_APPLY).setVi sible(false);

shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

display.dispose();
}
}

--------------080005050302080603070306--
Previous Topic:Eclipse Stammtisch in Frankfurt/Main 27.May.2009
Next Topic:1.1.0.M7 delayed
Goto Forum:
  


Current Time: Sun Dec 05 18:28:48 GMT 2021

Powered by FUDForum. Page generated in 0.02151 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top