use of com.biglybt.ui.common.table.TableSelectionListener in project BiglyBT by BiglySoftware.
the class OpenTorrentOptionsWindow method setupTVTorrents.
private void setupTVTorrents(Composite parent) {
GridLayout layout = new GridLayout();
layout.marginWidth = layout.marginHeight = 0;
layout.horizontalSpacing = layout.verticalSpacing = 0;
parent.setLayout(layout);
GridData gd;
// table
Composite table_area = new Composite(parent, SWT.NULL);
layout = new GridLayout();
layout.marginWidth = layout.marginHeight = 0;
layout.horizontalSpacing = layout.verticalSpacing = 0;
table_area.setLayout(layout);
gd = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(table_area, gd);
// toolbar area
Composite button_area = new Composite(parent, SWT.NULL);
layout = new GridLayout(5, false);
layout.marginWidth = layout.marginHeight = 0;
layout.horizontalSpacing = layout.verticalSpacing = 0;
layout.marginTop = 5;
button_area.setLayout(layout);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(button_area, gd);
Label label = new Label(button_area, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(label, gd);
buttonTorrentUp = new Button(button_area, SWT.PUSH);
buttonTorrentUp.setImage(loadImage("image.toolbar.up"));
buttonTorrentUp.setToolTipText(MessageText.getString("Button.moveUp"));
buttonTorrentUp.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
List<OpenTorrentInstance> selected = (List<OpenTorrentInstance>) (Object) tvTorrents.getSelectedDataSources();
if (selected.size() > 1) {
Collections.sort(selected, new Comparator<OpenTorrentInstance>() {
@Override
public int compare(OpenTorrentInstance o1, OpenTorrentInstance o2) {
return (o1.getIndex() - o2.getIndex());
}
});
}
boolean modified = false;
for (OpenTorrentInstance instance : selected) {
int index = instance.getIndex();
if (index > 0) {
open_instances.remove(instance);
open_instances.add(index - 1, instance);
modified = true;
}
}
if (modified) {
swt_updateTVTorrentButtons();
refreshTVTorrentIndexes();
}
}
});
buttonTorrentDown = new Button(button_area, SWT.PUSH);
buttonTorrentDown.setImage(loadImage("image.toolbar.down"));
buttonTorrentDown.setToolTipText(MessageText.getString("Button.moveDown"));
buttonTorrentDown.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
List<OpenTorrentInstance> selected = (List<OpenTorrentInstance>) (Object) tvTorrents.getSelectedDataSources();
if (selected.size() > 1) {
Collections.sort(selected, new Comparator<OpenTorrentInstance>() {
@Override
public int compare(OpenTorrentInstance o1, OpenTorrentInstance o2) {
return (o2.getIndex() - o1.getIndex());
}
});
}
boolean modified = false;
for (Object obj : selected) {
OpenTorrentInstance instance = (OpenTorrentInstance) obj;
int index = instance.getIndex();
if (index < open_instances.size() - 1) {
open_instances.remove(instance);
open_instances.add(index + 1, instance);
modified = true;
}
}
if (modified) {
swt_updateTVTorrentButtons();
refreshTVTorrentIndexes();
}
}
});
buttonTorrentRemove = new Button(button_area, SWT.PUSH);
buttonTorrentRemove.setToolTipText(MessageText.getString("OpenTorrentWindow.torrent.remove"));
buttonTorrentRemove.setImage(loadImage("image.toolbar.remove"));
buttonTorrentRemove.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
List<Object> selected = tvTorrents.getSelectedDataSources();
for (Object obj : selected) {
OpenTorrentInstance instance = (OpenTorrentInstance) obj;
removeInstance(instance, true);
}
}
});
buttonTorrentUp.setEnabled(false);
buttonTorrentDown.setEnabled(false);
buttonTorrentRemove.setEnabled(false);
label = new Label(button_area, SWT.NULL);
gd = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(label, gd);
TableColumnManager tcm = TableColumnManager.getInstance();
if (tcm.getDefaultColumnNames(TABLEID_TORRENTS) == null) {
tcm.registerColumn(OpenTorrentInstance.class, TableColumnOTOT_Position.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new TableColumnOTOT_Position(column);
}
});
tcm.registerColumn(OpenTorrentInstance.class, TableColumnOTOT_Name.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new TableColumnOTOT_Name(column);
}
});
tcm.registerColumn(OpenTorrentInstance.class, TableColumnOTOT_Size.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new TableColumnOTOT_Size(column);
}
});
tcm.setDefaultColumnNames(TABLEID_TORRENTS, new String[] { TableColumnOTOT_Position.COLUMN_ID, TableColumnOTOT_Name.COLUMN_ID, TableColumnOTOT_Size.COLUMN_ID });
tcm.setDefaultSortColumnName(TABLEID_TORRENTS, TableColumnOTOT_Position.COLUMN_ID);
}
tvTorrents = TableViewFactory.createTableViewSWT(OpenTorrentInstance.class, TABLEID_TORRENTS, TABLEID_TORRENTS, null, "#", SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
tvTorrents.initialize(table_area);
tvTorrents.setRowDefaultHeightEM(1.4f);
tvTorrents.addMenuFillListener(new TableViewSWTMenuFillListener() {
@Override
public void fillMenu(String sColumnName, Menu menu) {
final List<Object> selected = tvTorrents.getSelectedDataSources();
if (selected.size() > 0) {
final List<OpenTorrentInstance> instances = new ArrayList<>(selected.size());
final List<OpenTorrentInstance> non_simple_instances = new ArrayList<>();
boolean can_rtlf = false;
for (Object o : selected) {
OpenTorrentInstance oti = (OpenTorrentInstance) o;
instances.add(oti);
if (!oti.getOptions().isSimpleTorrent()) {
non_simple_instances.add(oti);
if (oti.canRemoveTopLevelFolder()) {
can_rtlf = true;
}
}
}
{
MenuItem item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(item, "OpenTorrentWindow.fileList.changeDestination");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (Object obj : selected) {
OpenTorrentInstance instance = (OpenTorrentInstance) obj;
instance.setSavePath();
}
}
});
}
{
MenuItem item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(item, "OpenTorrentWindow.tlf.remove");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (Object obj : selected) {
OpenTorrentInstance instance = (OpenTorrentInstance) obj;
if (instance.canRemoveTopLevelFolder()) {
instance.removeTopLevelFolder();
}
}
}
});
item.setEnabled(can_rtlf);
}
{
MenuItem item = new MenuItem(menu, SWT.CHECK);
item.setData(COConfigurationManager.getBooleanParameter("open.torrent.window.rename.on.tlf.change"));
Messages.setLanguageText(item, "OpenTorrentWindow.tlf.rename");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
COConfigurationManager.setParameter("open.torrent.window.rename.on.tlf.change", ((MenuItem) e.widget).getSelection());
}
});
item.setEnabled(non_simple_instances.size() > 0);
}
new MenuItem(menu, SWT.SEPARATOR);
MenuItem item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(item, "Button.remove");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (Object obj : selected) {
OpenTorrentInstance instance = (OpenTorrentInstance) obj;
removeInstance(instance, true);
}
}
});
new MenuItem(menu, SWT.SEPARATOR);
}
}
@Override
public void addThisColumnSubMenu(String sColumnName, Menu menuThisColumn) {
}
});
tvTorrents.addSelectionListener(new TableSelectionListener() {
@Override
public void selected(TableRowCore[] rows_not_used) {
TableRowCore[] rows = tvTorrents.getSelectedRows();
List<OpenTorrentInstance> instances = new ArrayList<>();
for (TableRowCore row : rows) {
instances.add((OpenTorrentInstance) row.getDataSource());
}
selectInstances(instances);
updateButtons();
}
@Override
public void mouseExit(TableRowCore row) {
}
@Override
public void mouseEnter(TableRowCore row) {
}
@Override
public void focusChanged(TableRowCore focus) {
}
@Override
public void deselected(TableRowCore[] rows) {
selected(rows);
}
private void updateButtons() {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
swt_updateTVTorrentButtons();
}
});
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
}
}, false);
}
use of com.biglybt.ui.common.table.TableSelectionListener in project BiglyBT by BiglySoftware.
the class SubscriptionWizard method createAvailableSubscriptionComposite.
private Composite createAvailableSubscriptionComposite(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
Label hsep1 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
Label hsep2 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
Label vsep = new Label(composite, SWT.SEPARATOR | SWT.VERTICAL);
Label subtitle1 = new Label(composite, SWT.NONE);
Label subtitle2 = new Label(composite, SWT.NONE);
subtitle1.setFont(subTitleFont);
subtitle2.setFont(subTitleFont);
subtitle1.setText(MessageText.getString("Wizard.Subscription.subscribe.library"));
subtitle2.setText(MessageText.getString("Wizard.Subscription.subscribe.subscriptions"));
libraryTable = new Table(composite, SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
final TableColumn torrentColumn = new TableColumn(libraryTable, SWT.NONE);
torrentColumn.setWidth(Utils.adjustPXForDPI(50));
final Composite compEmpty = new Composite(composite, SWT.NONE);
compEmpty.setBackground(Colors.getSystemColor(display, SWT.COLOR_WHITE));
compEmpty.setBackgroundMode(SWT.INHERIT_DEFAULT);
FillLayout fl = new FillLayout();
fl.marginHeight = 15;
fl.marginWidth = 15;
compEmpty.setLayout(fl);
compEmpty.setVisible(false);
final Link labelEmpty = new Link(compEmpty, SWT.WRAP);
labelEmpty.setText(MessageText.getString("Wizard.Subscription.subscribe.library.empty"));
labelEmpty.setFont(subTitleFont);
labelEmpty.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
labelEmpty.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.text != null && (event.text.startsWith("http://") || event.text.startsWith("https://"))) {
Utils.launch(event.text);
}
}
});
initColumns();
final Composite cTV = new Composite(composite, SWT.NONE);
cTV.setLayoutData(Utils.getFilledFormData());
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
cTV.setLayout(layout);
tvSubscriptions = TableViewFactory.createTableViewSWT(Subscription.class, TABLE_SUB_WIZ, TABLE_SUB_WIZ, new TableColumnCore[0], "SubWizRank", SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
tvSubscriptions.setMenuEnabled(false);
tvSubscriptions.setHeaderVisible(false);
tvSubscriptions.setRowDefaultHeightEM(1.4f);
tvSubscriptions.initialize(cTV);
tvSubscriptions.getComposite().addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
com.biglybt.pif.ui.tables.TableColumn tcName = tvSubscriptions.getTableColumn("SubWizName");
com.biglybt.pif.ui.tables.TableColumn tcRank = tvSubscriptions.getTableColumn("SubWizRank");
Rectangle clientArea = ((Composite) event.widget).getClientArea();
tcName.setWidthPX(clientArea.width - tcRank.getWidth() - 1);
}
});
tvSubscriptions.addSelectionListener(new TableSelectionListener() {
@Override
public void selected(TableRowCore[] row) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (tvSubscriptions.getSelectedRowsSize() == 0) {
addButton.setEnabled(false);
} else {
addButton.setEnabled(true);
TableRowCore[] rows = tvSubscriptions.getSelectedRows();
Subscription subscription = (Subscription) rows[0].getDataSource();
if (subscription.isSubscribed()) {
addButton.setEnabled(false);
} else {
addButton.setEnabled(true);
}
addButton.setData("subscription", subscription);
}
}
});
}
@Override
public void mouseExit(TableRowCore row) {
}
@Override
public void mouseEnter(TableRowCore row) {
}
@Override
public void focusChanged(TableRowCore focus) {
}
@Override
public void deselected(TableRowCore[] rows) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (tvSubscriptions.getSelectedRowsSize() == 0) {
addButton.setEnabled(false);
}
}
});
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
}
}, false);
UIUpdaterSWT.getInstance().addUpdater(new UIUpdatable() {
@Override
public void updateUI() {
if (tvSubscriptions != null) {
tvSubscriptions.refreshTable(false);
}
}
@Override
public String getUpdateUIName() {
return "SubWiz";
}
});
Listener resizeListener = new Listener() {
int last_width;
@Override
public void handleEvent(Event event) {
Table table = (Table) event.widget;
Rectangle rect = table.getClientArea();
int width = rect.width - 3;
if (width == last_width) {
return;
}
last_width = width;
int nbColumns = table.getColumnCount();
if (nbColumns == 1) {
table.getColumns()[0].setWidth(width);
}
((Table) event.widget).update();
}
};
// subscriptionTable.addListener(SWT.Resize , resizeListener);
libraryTable.addListener(SWT.Resize, resizeListener);
final Listener selectionListener = new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
subscriptions = (Subscription[]) item.getData("subscriptions");
tvSubscriptions.removeDataSources(tvSubscriptions.getDataSources().toArray(new Subscription[0]));
if (subscriptions != null) {
tvSubscriptions.addDataSources(subscriptions);
}
tvSubscriptions.processDataSourceQueueSync();
addButton.setEnabled(false);
addButton.setData("subscription", null);
tvSubscriptions.setSelectedRows(new TableRowCore[0]);
if (subscriptions != null && subscriptions.length > 0) {
TableRowCore row = tvSubscriptions.getRow(subscriptions[0]);
if (row != null) {
row.setSelected(true);
}
}
}
};
libraryTable.addListener(SWT.Selection, selectionListener);
if (availableSubscriptions != null) {
libraryTable.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = libraryTable.indexOf(item);
SubscriptionDownloadDetails subInfo = availableSubscriptions[index];
item.setText(subInfo.getDownload().getDisplayName());
item.setData("subscriptions", subInfo.getSubscriptions());
boolean isSubscribed = false;
Subscription[] subs = subInfo.getSubscriptions();
for (int i = 0; i < subs.length; i++) {
if (subs[i].isSubscribed())
isSubscribed = true;
}
if (isSubscribed) {
item.setForeground(Colors.getSystemColor(display, SWT.COLOR_GRAY));
}
if (subInfo.getDownload() == download) {
libraryTable.setSelection(item);
selectionListener.handleEvent(event);
}
if (index == 0 && download == null) {
libraryTable.setSelection(item);
selectionListener.handleEvent(event);
}
if (libraryTable.getSelectionIndex() == index) {
// If the item was already selected and we got the SetData afterwards, then let's populate the
// subscriptionsTable
selectionListener.handleEvent(event);
}
}
});
libraryTable.setItemCount(availableSubscriptions.length);
if (availableSubscriptions.length == 0) {
libraryTable.setVisible(false);
compEmpty.setVisible(true);
}
} else {
// Test code
libraryTable.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = libraryTable.indexOf(item);
item.setText("test " + index);
}
});
libraryTable.setItemCount(20);
}
addButton.setEnabled(false);
addButton.setData("subscription", null);
// final Image rssIcon = imageLoader.getImage("icon_rss");
libraryTable.addListener(SWT.MeasureItem, new Listener() {
@Override
public void handleEvent(Event event) {
event.height = 20;
}
});
FormLayout formLayout = new FormLayout();
composite.setLayout(formLayout);
FormData data;
data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(40, 0);
data.bottom = new FormAttachment(100, 0);
vsep.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(0, 5);
data.right = new FormAttachment(vsep, 0);
data.left = new FormAttachment(0, 5);
subtitle1.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(0, 5);
data.left = new FormAttachment(vsep, 5);
data.right = new FormAttachment(100, 0);
subtitle2.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(subtitle1, 5);
data.right = new FormAttachment(vsep, 0);
data.left = new FormAttachment(0, 0);
hsep1.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(subtitle2, 5);
data.left = new FormAttachment(vsep, -1);
data.right = new FormAttachment(100, 0);
hsep2.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(hsep1, 0);
data.right = new FormAttachment(vsep, 0);
data.left = new FormAttachment(0, 0);
data.bottom = new FormAttachment(100, 0);
if (availableSubscriptions != null && availableSubscriptions.length > 0) {
libraryTable.setLayoutData(data);
} else {
// hack: dispose libraryTable as it's not needed and draws over controls
// (makes a white box covering text). Would be smarter to not
// create the libraryTable at all..
libraryTable.dispose();
cancelButton.setFocus();
shell.setDefaultButton(cancelButton);
compEmpty.setLayoutData(data);
}
data = new FormData();
data.top = new FormAttachment(hsep2, 0);
data.left = new FormAttachment(vsep, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
cTV.setLayoutData(data);
return composite;
}
Aggregations