use of com.biglybt.ui.common.table.impl.TableColumnManager in project BiglyBT by BiglySoftware.
the class ColumnStream method preAdd.
// @see TableColumnImpl#preAdd()
@Override
public void preAdd() {
if (!isFirstLoad() || getPosition() >= 0 || getColumnAdded()) {
return;
}
TableColumnManager tcManager = TableColumnManager.getInstance();
TableColumnInfo columnInfoTAN = tcManager.getColumnInfo(null, getTableID(), ColumnThumbAndName.COLUMN_ID);
if (columnInfoTAN != null) {
TableColumn column = columnInfoTAN.getColumn();
if (column != null) {
int position = column.getPosition();
if (position >= 0) {
setPosition(position + 1);
}
}
}
}
use of com.biglybt.ui.common.table.impl.TableColumnManager in project BiglyBT by BiglySoftware.
the class SBC_DevicesView method initColumns.
/**
* @since 4.1.0.5
*/
private void initColumns(Core core) {
if (columnsAdded) {
return;
}
columnsAdded = true;
UIManager uiManager = PluginInitializer.getDefaultInterface().getUIManager();
TableManager tableManager = uiManager.getTableManager();
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Rank.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Rank(column);
if (!column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setVisible(false);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnThumbnail.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnThumbnail(column);
column.setWidth(70);
column.setVisible(false);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Name.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Name(column);
if (column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setWidth(200);
} else if (!column.getTableID().endsWith(":type=1")) {
column.setWidth(140);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Duration.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Duration(column);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Device.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Device(column);
column.setVisible(false);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Profile.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Profile(column);
if (column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setWidth(70);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Resolution.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Resolution(column);
column.setVisible(false);
if (column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setWidth(95);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Status.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Status(column);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Completion.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Completion(column);
column.setWidth(145);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_CopiedToDevice.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_CopiedToDevice(column);
if (column.getTableID().endsWith(":type=1") || column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setVisible(false);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Category.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Category(column);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Tags.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Tags(column);
}
});
TableColumnManager tcm = TableColumnManager.getInstance();
String[] defaultLibraryColumns = { ColumnTJ_Rank.COLUMN_ID, ColumnTJ_Name.COLUMN_ID, ColumnTJ_Duration.COLUMN_ID, ColumnTJ_Device.COLUMN_ID, ColumnTJ_Status.COLUMN_ID, ColumnTJ_Completion.COLUMN_ID };
tcm.setDefaultColumnNames(TABLE_TRANSCODE_QUEUE, defaultLibraryColumns);
String[] defaultQColumns = { ColumnTJ_Name.COLUMN_ID, ColumnTJ_Duration.COLUMN_ID, ColumnTJ_Profile.COLUMN_ID, ColumnTJ_Status.COLUMN_ID, ColumnTJ_Completion.COLUMN_ID };
tcm.setDefaultColumnNames(TABLE_DEVICE_LIBRARY, defaultQColumns);
}
use of com.biglybt.ui.common.table.impl.TableColumnManager 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.impl.TableColumnManager in project BiglyBT by BiglySoftware.
the class TorrentInfoView method initialize.
private void initialize(Composite composite) {
this.parent = composite;
if (download_manager == null) {
return;
}
// I don't want to waste my time :) [tux]
if (sc != null && !sc.isDisposed()) {
sc.dispose();
}
sc = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL);
sc.getVerticalBar().setIncrement(16);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
Utils.setLayoutData(sc, gridData);
outer_panel = sc;
Composite panel = new Composite(sc, SWT.NULL);
sc.setContent(panel);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 1;
panel.setLayout(layout);
// int userMode = COConfigurationManager.getIntParameter("User Mode");
// header
Composite cHeader = new Composite(panel, SWT.BORDER);
GridLayout configLayout = new GridLayout();
configLayout.marginHeight = 3;
configLayout.marginWidth = 0;
cHeader.setLayout(configLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
Utils.setLayoutData(cHeader, gridData);
Display d = panel.getDisplay();
cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
Label lHeader = new Label(cHeader, SWT.NULL);
lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
FontData[] fontData = lHeader.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
int fontHeight = (int) (fontData[0].getHeight() * 1.2);
fontData[0].setHeight(fontHeight);
headerFont = new Font(d, fontData);
lHeader.setFont(headerFont);
lHeader.setText(" " + MessageText.getString("authenticator.torrent") + " : " + download_manager.getDisplayName().replaceAll("&", "&&"));
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
Utils.setLayoutData(lHeader, gridData);
Composite gTorrentInfo = new Composite(panel, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
Utils.setLayoutData(gTorrentInfo, gridData);
layout = new GridLayout();
layout.numColumns = 2;
gTorrentInfo.setLayout(layout);
// torrent encoding
Label label = new Label(gTorrentInfo, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(label, gridData);
label.setText(MessageText.getString("TorrentInfoView.torrent.encoding") + ": ");
TOTorrent torrent = download_manager.getTorrent();
BufferedLabel blabel = new BufferedLabel(gTorrentInfo, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(blabel, gridData);
blabel.setText(torrent == null ? "" : LocaleTorrentUtil.getCurrentTorrentEncoding(torrent));
// trackers
label = new Label(gTorrentInfo, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(label, gridData);
label.setText(MessageText.getString("label.tracker") + ": ");
String trackers = "";
if (torrent != null) {
TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
List<String> tracker_list = new ArrayList<>();
URL url = torrent.getAnnounceURL();
tracker_list.add(url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort())));
for (int i = 0; i < sets.length; i++) {
TOTorrentAnnounceURLSet set = sets[i];
URL[] urls = set.getAnnounceURLs();
for (int j = 0; j < urls.length; j++) {
url = urls[j];
String str = url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort()));
if (!tracker_list.contains(str)) {
tracker_list.add(str);
}
}
}
TRTrackerAnnouncer announcer = download_manager.getTrackerClient();
URL active_url = null;
if (announcer != null) {
active_url = announcer.getTrackerURL();
} else {
TRTrackerScraperResponse scrape = download_manager.getTrackerScrapeResponse();
if (scrape != null) {
active_url = scrape.getURL();
}
}
if (active_url == null) {
active_url = torrent.getAnnounceURL();
}
trackers = active_url.getHost() + (active_url.getPort() == -1 ? "" : (":" + active_url.getPort()));
tracker_list.remove(trackers);
if (tracker_list.size() > 0) {
trackers += " (";
for (int i = 0; i < tracker_list.size(); i++) {
trackers += (i == 0 ? "" : ", ") + tracker_list.get(i);
}
trackers += ")";
}
}
blabel = new BufferedLabel(gTorrentInfo, SWT.WRAP);
Utils.setLayoutData(blabel, Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL));
blabel.setText(trackers);
// columns
Group gColumns = new Group(panel, SWT.NULL);
Messages.setLanguageText(gColumns, "TorrentInfoView.columns");
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(gColumns, gridData);
layout = new GridLayout();
layout.numColumns = 4;
gColumns.setLayout(layout);
Map<String, FakeTableCell> usable_cols = new HashMap<>();
TableColumnManager col_man = TableColumnManager.getInstance();
TableColumnCore[][] cols_sets = { col_man.getAllTableColumnCoreAsArray(DownloadTypeIncomplete.class, TableManager.TABLE_MYTORRENTS_INCOMPLETE), col_man.getAllTableColumnCoreAsArray(DownloadTypeComplete.class, TableManager.TABLE_MYTORRENTS_COMPLETE) };
for (int i = 0; i < cols_sets.length; i++) {
TableColumnCore[] cols = cols_sets[i];
for (int j = 0; j < cols.length; j++) {
TableColumnCore col = cols[j];
String id = col.getName();
if (usable_cols.containsKey(id)) {
continue;
}
FakeTableCell fakeTableCell = null;
try {
fakeTableCell = new FakeTableCell(col, download_manager);
fakeTableCell.setOrentation(SWT.LEFT);
fakeTableCell.setWrapText(false);
col.invokeCellAddedListeners(fakeTableCell);
// One refresh to see if it throws up
fakeTableCell.refresh();
usable_cols.put(id, fakeTableCell);
} catch (Throwable t) {
// System.out.println("not usable col: " + id + " - " + Debug.getCompressedStackTrace());
try {
if (fakeTableCell != null) {
fakeTableCell.dispose();
}
} catch (Throwable t2) {
// ignore;
}
}
}
}
Collection<FakeTableCell> values = usable_cols.values();
cells = new FakeTableCell[values.size()];
values.toArray(cells);
Arrays.sort(cells, new Comparator<FakeTableCell>() {
@Override
public int compare(FakeTableCell o1, FakeTableCell o2) {
TableColumnCore c1 = (TableColumnCore) o1.getTableColumn();
TableColumnCore c2 = (TableColumnCore) o2.getTableColumn();
String key1 = MessageText.getString(c1.getTitleLanguageKey());
String key2 = MessageText.getString(c2.getTitleLanguageKey());
return key1.compareToIgnoreCase(key2);
}
});
for (int i = 0; i < cells.length; i++) {
final FakeTableCell cell = cells[i];
label = new Label(gColumns, SWT.NULL);
gridData = new GridData();
if (i % 2 == 1) {
gridData.horizontalIndent = 16;
}
Utils.setLayoutData(label, gridData);
String key = ((TableColumnCore) cell.getTableColumn()).getTitleLanguageKey();
label.setText(MessageText.getString(key) + ": ");
label.setToolTipText(MessageText.getString(key + ".info", ""));
final Composite c = new Composite(gColumns, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.heightHint = 16;
Utils.setLayoutData(c, gridData);
cell.setControl(c);
cell.invalidate();
cell.refresh();
c.addListener(SWT.MouseHover, new Listener() {
@Override
public void handleEvent(Event event) {
Object toolTip = cell.getToolTip();
if (toolTip instanceof String) {
String s = (String) toolTip;
c.setToolTipText(s);
}
}
});
}
refresh();
sc.setMinSize(panel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
use of com.biglybt.ui.common.table.impl.TableColumnManager in project BiglyBT by BiglySoftware.
the class SBC_SubscriptionResultsView method initTable.
private void initTable(Composite control) {
tv_subs_results = TableViewFactory.createTableViewSWT(SBC_SubscriptionResult.class, TABLE_SR, TABLE_SR, new TableColumnCore[0], ColumnSearchSubResultAge.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
TableColumnManager tableManager = TableColumnManager.getInstance();
tableManager.setDefaultColumnNames(TABLE_SR, new String[] { ColumnSubResultNew.COLUMN_ID, ColumnSearchSubResultType.COLUMN_ID, ColumnSearchSubResultName.COLUMN_ID, ColumnSearchSubResultActions.COLUMN_ID, ColumnSearchSubResultSize.COLUMN_ID, ColumnSearchSubResultSeedsPeers.COLUMN_ID, ColumnSearchSubResultRatings.COLUMN_ID, ColumnSearchSubResultAge.COLUMN_ID, ColumnSearchSubResultRank.COLUMN_ID, ColumnSearchSubResultCategory.COLUMN_ID });
tableManager.setDefaultSortColumnName(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
TableColumnCore tcc = tableManager.getTableColumnCore(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
if (tcc != null) {
tcc.setDefaultSortAscending(true);
}
if (txtFilter != null) {
tv_subs_results.enableFilterCheck(txtFilter, this);
}
tv_subs_results.setRowDefaultHeight(COConfigurationManager.getIntParameter("Search Subs Row Height"));
SWTSkinObject soSizeSlider = getSkinObject("table-size-slider");
if (soSizeSlider instanceof SWTSkinObjectContainer) {
SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
if (!tv_subs_results.enableSizeSlider(so.getComposite(), 16, 100)) {
so.setVisible(false);
}
}
table_parent = new Composite(control, SWT.NONE);
table_parent.setLayoutData(Utils.getFilledFormData());
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
table_parent.setLayout(layout);
tv_subs_results.addSelectionListener(new TableSelectionListener() {
@Override
public void selected(TableRowCore[] _rows) {
updateSelectedContent();
}
@Override
public void mouseExit(TableRowCore row) {
}
@Override
public void mouseEnter(TableRowCore row) {
}
@Override
public void focusChanged(TableRowCore focus) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
@Override
public void deselected(TableRowCore[] rows) {
updateSelectedContent();
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
SBC_SubscriptionResult rc = (SBC_SubscriptionResult) rows[0].getDataSource();
SBC_SearchResultsView.downloadAction(rc);
}
}
private void updateSelectedContent() {
TableRowCore[] rows = tv_subs_results.getSelectedRows();
ArrayList<ISelectedContent> valid = new ArrayList<>();
last_selected_content.clear();
for (int i = 0; i < rows.length; i++) {
SBC_SubscriptionResult rc = (SBC_SubscriptionResult) rows[i].getDataSource();
last_selected_content.add(rc);
byte[] hash = rc.getHash();
if (hash != null && hash.length > 0) {
SelectedContent sc = new SelectedContent(Base32.encode(hash), rc.getName());
sc.setDownloadInfo(new DownloadUrlInfo(getDownloadURI(rc)));
valid.add(sc);
}
}
ISelectedContent[] sels = valid.toArray(new ISelectedContent[valid.size()]);
SelectedContentManager.changeCurrentlySelectedContent("IconBarEnabler", sels, tv_subs_results);
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
}, false);
tv_subs_results.addLifeCycleListener(new TableLifeCycleListener() {
@Override
public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
if (eventType == TableLifeCycleListener.EVENT_TABLELIFECYCLE_INITIALIZED) {
reconcileResults(ds);
}
}
});
tv_subs_results.addMenuFillListener(new TableViewSWTMenuFillListener() {
@Override
public void fillMenu(String sColumnName, Menu menu) {
Object[] _related_content = tv_subs_results.getSelectedDataSources().toArray();
final SBC_SubscriptionResult[] results = new SBC_SubscriptionResult[_related_content.length];
System.arraycopy(_related_content, 0, results, 0, results.length);
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(MessageText.getString("label.copy.url.to.clip"));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
StringBuffer buffer = new StringBuffer(1024);
for (SBC_SubscriptionResult result : results) {
if (buffer.length() > 0) {
buffer.append("\r\n");
}
buffer.append(getDownloadURI(result));
}
ClipboardCopy.copyToClipBoard(buffer.toString());
}
});
item.setEnabled(results.length > 0);
SearchSubsUtils.addMenu(results, menu);
new MenuItem(menu, SWT.SEPARATOR);
if (results.length == 1) {
if (SearchSubsUtils.addMenu(results[0], menu)) {
new MenuItem(menu, SWT.SEPARATOR);
}
}
final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
remove_item.setText(MessageText.getString("azbuddy.ui.menu.remove"));
Utils.setMenuItemImage(remove_item, "delete");
remove_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
userDelete(results);
}
});
remove_item.setEnabled(results.length > 0);
new MenuItem(menu, SWT.SEPARATOR);
}
@Override
public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
}
});
tv_subs_results.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
Object[] selected;
synchronized (this) {
if (tv_subs_results == null) {
selected = new Object[0];
} else {
selected = tv_subs_results.getSelectedDataSources().toArray();
}
}
SBC_SubscriptionResult[] content = new SBC_SubscriptionResult[selected.length];
for (int i = 0; i < content.length; i++) {
content[i] = (SBC_SubscriptionResult) selected[i];
}
userDelete(content);
e.doit = false;
}
}
@Override
public void keyReleased(KeyEvent arg0) {
}
});
/*
if (ds instanceof RCMItemSubView) {
tv_related_content.addCountChangeListener(new TableCountChangeListener() {
public void rowRemoved(TableRowCore row) {
updateCount();
}
public void rowAdded(TableRowCore row) {
updateCount();
}
private void updateCount() {
int size = tv_related_content == null ? 0 : tv_related_content.size(false);
((RCMItemSubView) ds).setCount(size);
}
});
((RCMItemSubView) ds).setCount(0);
}
*/
tv_subs_results.initialize(table_parent);
control.layout(true);
}
Aggregations