Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow to collapse items in a list
  • Loading branch information
pescuma committed Oct 14, 2013
1 parent f08e462 commit e13be74
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 60 deletions.
27 changes: 23 additions & 4 deletions examples/org/pescuma/jfg/examples/swt/SimpleDialog.java
Expand Up @@ -11,9 +11,9 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.pescuma.jfg.gui.swt.JfgFormComposite;
import org.pescuma.jfg.gui.swt.JfgFormData;
import org.pescuma.jfg.gui.swt.JfgFormComposite.LayoutEvent;
import org.pescuma.jfg.gui.swt.JfgFormComposite.LayoutListener;
import org.pescuma.jfg.gui.swt.JfgFormData;
import org.pescuma.jfg.reflect.ReflectionGroup;

public class SimpleDialog
Expand All @@ -33,7 +33,25 @@ public static void main(String[] args)
TestClass obj = new TestClass();

// Create the form
final JfgFormComposite form = new JfgFormComposite(contents, SWT.NONE, new JfgFormData(JfgFormData.DIALOG));
JfgFormData data = new JfgFormData(JfgFormData.DIALOG);

// To allow the expand/collapse the subitems in the subs list, uncomment
// the following line
// And maybe add a name field as the first item of TestSub class?
//
// data.configure(JfgHelper.attribute(TestClass.class,
// "subs")).setWidgetData(
// new ObjectListGuiWidget.Data().allowToCollapse());
//
// or
//
// data.allowCollapseObjectsInListByDefault = true;

// Depending on your objects depth, you may need this too
//
// data.maxAttributeSubLevels = 5;

final JfgFormComposite form = new JfgFormComposite(contents, SWT.NONE, data);
form.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

// Add elements to form
Expand All @@ -56,6 +74,7 @@ public void layoutChanged(LayoutEvent e)
// Add an ok button
Button ok = new Button(shell, SWT.PUSH);
ok.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event)
{
form.copyToModel();
Expand All @@ -65,8 +84,8 @@ public void handleEvent(Event event)
ok.setText("Ok");

// If you want that the form appears without scroll bars, use this line.
// The problem with it is that depending on the contents of your objects the form will have
// a different size.
// The problem with it is that depending on the contents of your objects
// the form will have a different size.
form.copyToGUI();

shell.setText("Simple Dialog");
Expand Down
Binary file added icons/collapse.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/expand.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion src/org/pescuma/jfg/gui/ObjectListGuiWidget.java
Expand Up @@ -2,6 +2,24 @@

public interface ObjectListGuiWidget extends GuiWidget
{
void removeAllObjects();
void removeAllObjects();

void addObject(Object obj);

public static class Data
{
public boolean collapse = false;

public Data allowToCollapse()
{
collapse = true;
return this;
}

public Data dontAllowToCollapse()
{
collapse = false;
return this;
}
}
}
27 changes: 18 additions & 9 deletions src/org/pescuma/jfg/gui/swt/InlineObjectListSWTWidget.java
Expand Up @@ -79,13 +79,13 @@ public void handleEvent(Event event)
}
}

protected void buildAttributeInsideList(Attribute itemAttribute, boolean addingNew)
protected void buildAttributeInsideList(Attribute itemAttribute, boolean addingNewAndEmpty)
{
final Item item = new Item();

Composite composite = listLayout.startListItem(list.getName());
Composite composite = listLayout.startListItem(list.getName(), addingNewAndEmpty);

buildInnerAttribute(composite, itemAttribute, addingNew);
buildInnerAttribute(composite, itemAttribute);

Control remove = null;
if (list.canWrite())
Expand All @@ -109,7 +109,7 @@ public void handleEvent(Event event)
items.add(item);
}

private void buildInnerAttribute(Composite composite, Attribute itemAttribute, boolean addingNew)
private void buildInnerAttribute(Composite composite, Attribute itemAttribute)
{
// If someone set the type, lets build it
FieldConfig config = data.fieldsConfig.get(itemAttribute.getName());
Expand Down Expand Up @@ -279,11 +279,20 @@ public void copyToGUI()
@Override
public void addObject(Object obj)
{
Attribute el = list.createNewElement();
el.setValue(obj);

buildAttributeInsideList(el, true);
onWidgetModify();
Shell shell = frame.getShell();
shell.setRedraw(false);
try
{
Attribute el = list.createNewElement();
el.setValue(obj);

buildAttributeInsideList(el, false);
onWidgetModify();
}
finally
{
shell.setRedraw(true);
}
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/org/pescuma/jfg/gui/swt/JfgFormData.java
Expand Up @@ -91,6 +91,8 @@ enum ModelUpdateStrategy

public boolean markFieldsWhithUncommitedChanges = true;

public boolean allowCollapseObjectsInListByDefault = false;

public JfgFormData()
{
this(-1);
Expand Down
3 changes: 3 additions & 0 deletions src/org/pescuma/jfg/gui/swt/SWTComponentFactory.java
Expand Up @@ -50,7 +50,10 @@ public interface SWTComponentFactory

Control createFlatButton(Composite parent, String text, String image, Listener selectionListener);

void changeFlatButtonIcon(Control expand, String string);

CalendarCombo createCalendarCombo(Composite parent, int style, ISettings defaultSettings);

DateTime createDateTime(Composite parent, int style);

}
4 changes: 2 additions & 2 deletions src/org/pescuma/jfg/gui/swt/SWTLayoutBuilder.java
Expand Up @@ -37,10 +37,10 @@ static interface ListItem {}
Composite getParentForAddMore();
void addAddMore(Control addMore);

Composite startListItem(String attributeName);
Composite startListItem(String attributeName, boolean addingNewAndEmpty);
Composite getParentForRemove();
ListItem endListItem(String attributeName, Control remove);
void removeListItem(ListItem item);
void removeListItem (ListItem item);
void moveAfter(ListItem baseItem, ListItem itemToMove);
}
}
35 changes: 22 additions & 13 deletions src/org/pescuma/jfg/gui/swt/SWTSimpleComponentFactory.java
Expand Up @@ -27,6 +27,8 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

public class SWTSimpleComponentFactory implements SWTComponentFactory
{
Expand Down Expand Up @@ -88,20 +90,27 @@ public Button createButton(Composite parent, int style)
@Override
public Control createFlatButton(Composite parent, String text, String image, Listener selectionListener)
{
// ToolBar addMore = new ToolBar(parent, SWT.FLAT | SWT.RIGHT | SWT.NO_BACKGROUND);
// ToolItem item = new ToolItem(addMore, SWT.PUSH);
// item.setText(text);
// item.setImage(new Image(item.getDisplay(), image));
// item.addListener(SWT.Selection, selectionListener);
// item.addListener(SWT.DefaultSelection, selectionListener);
//
// return addMore;
ToolBar toolbar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT | SWT.NO_BACKGROUND);
ToolItem item = new ToolItem(toolbar, SWT.PUSH);
item.setText(text);
item.setImage(resourcesManager.newImage(image));
item.addListener(SWT.Selection, selectionListener);
item.addListener(SWT.DefaultSelection, selectionListener);

Button button = new Button(parent, SWT.PUSH | SWT.FLAT);
button.setText(text);
button.setImage(resourcesManager.newImage(image));
button.addListener(SWT.Selection, selectionListener);
return button;
return toolbar;
//
// Button button = new Button(parent, SWT.PUSH | SWT.FLAT);
// button.setText(text);
// button.setImage(resourcesManager.newImage(image));
// button.addListener(SWT.Selection, selectionListener);
// return button;
}

@Override
public void changeFlatButtonIcon(Control expand, String image)
{
ToolBar toolbar = (ToolBar) expand;
toolbar.getItem(0).setImage(resourcesManager.newImage(image));
}

@Override
Expand Down

0 comments on commit e13be74

Please sign in to comment.