X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2Fwidgets%2FTable.java;h=0d3ee6ddcdac1fdc825b1ff0471417cf8b6c1904;hp=d35220a55a69e91b852c07ca5b103f2f4d0e123e;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Table.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Table.java index d35220a55..0d3ee6ddc 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Table.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Table.java @@ -1,167 +1,167 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Association for Decentralized Information Management - * in Industry THTH ry. - * 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.swt.widgets; - -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.TableItem; -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory; -import org.simantics.browsing.ui.swt.widgets.impl.Widget; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.procedure.Listener; -import org.simantics.utils.datastructures.Pair; -import org.simantics.utils.ui.SWTUtils; - -public class Table extends WidgetImpl { - - private ReadFactory>> itemFactory; - private ReadFactory selectionFactory; - private CopyOnWriteArrayList selectionListeners = new CopyOnWriteArrayList(); - - final private org.eclipse.swt.widgets.Table table; - - public Table(Composite parent, WidgetSupport support, int style) { - super(support); - table = new org.eclipse.swt.widgets.Table(parent, style); - table.setData("org.simantics.browsing.ui.widgets.Combo", this); - support.register(this); - } - - public void setItemFactory(ReadFactory>> itemFactory) { - this.itemFactory = itemFactory; - } - - public void setSelectionFactory(ReadFactory selectionFactory) { - this.selectionFactory = selectionFactory; - } - - public org.eclipse.swt.widgets.Table getWidget() { - return table; - } - - @Override - public Control getControl() { - return table; - } - - @Override - public void setInput(ISessionContext context, Object input) { - - if (selectionListeners != null) { - for (SelectionListener listener : selectionListeners) { - if(listener instanceof Widget) { - ((Widget) listener).setInput(context, input); - } - } - } - - if(itemFactory != null) { - itemFactory.listen(context, input, new Listener>>() { - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public void execute(final List> items) { - SWTUtils.asyncExec(table, new Runnable() { - - @Override - public void run() { - if(isDisposed()) return; -// System.out.println("Combo received new items: " + items.size()); - for(SelectionListener listener : selectionListeners) table.removeSelectionListener(listener); - table.setData(items); - try { - table.removeAll(); - } catch (Throwable t) { - t.printStackTrace(); - } - //table.setItemCount(items.size()); - for(Pair key : items) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText(key.first); - item.setData(key.second); - } - String selectionKey = (String)table.getData("_SelectionKey"); - if(selectionKey != null) { - Integer selectionIndex = (Integer)table.getData(selectionKey); - if(selectionIndex != null) table.select(selectionIndex); - } - for(SelectionListener listener : selectionListeners) table.addSelectionListener(listener); - - //label.setSize(200, 20); -// label.getParent().layout(); -// label.getParent().getParent().layout(); - } - - }); - } - - @Override - public boolean isDisposed() { - return table.isDisposed(); - } - - }); - } - - if(selectionFactory != null) { - selectionFactory.listen(context, input, new Listener() { - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public void execute(final String selectionKey) { - SWTUtils.asyncExec(table, new Runnable() { - - @Override - public void run() { - if(isDisposed()) return; - if(selectionKey == null) return; -// System.out.println("Combo received new selection key: " + selectionKey); - - table.setData("_SelectionKey", selectionKey); - Integer selectionIndex = (Integer)table.getData(selectionKey); - if(selectionIndex != null) table.select(selectionIndex); - - } - - }); - } - - @Override - public boolean isDisposed() { - return table.isDisposed(); - } - - }); - } - - } - - public synchronized void addSelectionListener(SelectionListener listener) { - selectionListeners.add(listener); - table.addSelectionListener(listener); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management + * in Industry THTH ry. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.swt.widgets; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.TableItem; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.ui.SWTUtils; + +public class Table extends WidgetImpl { + + private ReadFactory>> itemFactory; + private ReadFactory selectionFactory; + private CopyOnWriteArrayList selectionListeners = new CopyOnWriteArrayList(); + + final private org.eclipse.swt.widgets.Table table; + + public Table(Composite parent, WidgetSupport support, int style) { + super(support); + table = new org.eclipse.swt.widgets.Table(parent, style); + table.setData("org.simantics.browsing.ui.widgets.Combo", this); + support.register(this); + } + + public void setItemFactory(ReadFactory>> itemFactory) { + this.itemFactory = itemFactory; + } + + public void setSelectionFactory(ReadFactory selectionFactory) { + this.selectionFactory = selectionFactory; + } + + public org.eclipse.swt.widgets.Table getWidget() { + return table; + } + + @Override + public Control getControl() { + return table; + } + + @Override + public void setInput(ISessionContext context, Object input) { + + if (selectionListeners != null) { + for (SelectionListener listener : selectionListeners) { + if(listener instanceof Widget) { + ((Widget) listener).setInput(context, input); + } + } + } + + if(itemFactory != null) { + itemFactory.listen(context, input, new Listener>>() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(final List> items) { + SWTUtils.asyncExec(table, new Runnable() { + + @Override + public void run() { + if(isDisposed()) return; +// System.out.println("Combo received new items: " + items.size()); + for(SelectionListener listener : selectionListeners) table.removeSelectionListener(listener); + table.setData(items); + try { + table.removeAll(); + } catch (Throwable t) { + t.printStackTrace(); + } + //table.setItemCount(items.size()); + for(Pair key : items) { + TableItem item = new TableItem (table, SWT.NONE); + item.setText(key.first); + item.setData(key.second); + } + String selectionKey = (String)table.getData("_SelectionKey"); + if(selectionKey != null) { + Integer selectionIndex = (Integer)table.getData(selectionKey); + if(selectionIndex != null) table.select(selectionIndex); + } + for(SelectionListener listener : selectionListeners) table.addSelectionListener(listener); + + //label.setSize(200, 20); +// label.getParent().layout(); +// label.getParent().getParent().layout(); + } + + }); + } + + @Override + public boolean isDisposed() { + return table.isDisposed(); + } + + }); + } + + if(selectionFactory != null) { + selectionFactory.listen(context, input, new Listener() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(final String selectionKey) { + SWTUtils.asyncExec(table, new Runnable() { + + @Override + public void run() { + if(isDisposed()) return; + if(selectionKey == null) return; +// System.out.println("Combo received new selection key: " + selectionKey); + + table.setData("_SelectionKey", selectionKey); + Integer selectionIndex = (Integer)table.getData(selectionKey); + if(selectionIndex != null) table.select(selectionIndex); + + } + + }); + } + + @Override + public boolean isDisposed() { + return table.isDisposed(); + } + + }); + } + + } + + public synchronized void addSelectionListener(SelectionListener listener) { + selectionListeners.add(listener); + table.addSelectionListener(listener); + } + +}