use of com.biglybt.ui.common.table.impl.TableColumnManager in project BiglyBT by BiglySoftware.
the class SBC_TagDiscovery method initColumns.
protected void initColumns() {
synchronized (SBC_TagDiscovery.class) {
if (columnsAdded) {
return;
}
columnsAdded = true;
}
TableColumnManager tableManager = TableColumnManager.getInstance();
tableManager.registerColumn(TagDiscovery.class, ColumnTagDiscoveryName.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTagDiscoveryName(column);
}
});
tableManager.registerColumn(TagDiscovery.class, ColumnTagDiscoveryTorrent.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTagDiscoveryTorrent(column);
}
});
tableManager.registerColumn(TagDiscovery.class, ColumnTagDiscoveryAddedOn.COLUMN_ID, new TableColumnCoreCreationListener() {
@Override
public TableColumnCore createTableColumnCore(Class<?> forDataSourceType, String tableID, String columnID) {
return new ColumnDateSizer(TagDiscovery.class, columnID, TableColumnCreator.DATE_COLUMN_WIDTH, tableID) {
};
}
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTagDiscoveryAddedOn(column);
}
});
tableManager.registerColumn(TagDiscovery.class, ColumnTagDiscoveryNetwork.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTagDiscoveryNetwork(column);
}
});
tableManager.setDefaultColumnNames(TABLE_TAGDISCOVERY, new String[] { ColumnTagDiscoveryName.COLUMN_ID, ColumnTagDiscoveryTorrent.COLUMN_ID, ColumnTagDiscoveryAddedOn.COLUMN_ID });
tableManager.setDefaultSortColumnName(TABLE_TAGDISCOVERY, ColumnTagDiscoveryAddedOn.COLUMN_ID);
}
use of com.biglybt.ui.common.table.impl.TableColumnManager in project BiglyBT by BiglySoftware.
the class ColumnTC_NameInfo method cellPaint.
// @see com.biglybt.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, com.biglybt.ui.swt.views.table.TableCellSWT)
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
TableColumnCore column = (TableColumnCore) cell.getDataSource();
String raw_key = column.getTitleLanguageKey(false);
String current_key = column.getTitleLanguageKey(true);
Rectangle bounds = cell.getBounds();
if (bounds == null || bounds.isEmpty()) {
return;
}
Font fontDefault = gc.getFont();
if (fontHeader == null) {
FontData[] fontData = gc.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
fontData[0].setHeight(fontData[0].getHeight() + 1);
fontHeader = new Font(gc.getDevice(), fontData);
}
gc.setFont(fontHeader);
bounds.y += 3;
bounds.x += 7;
bounds.width -= 14;
String name = MessageText.getString(raw_key, column.getName());
if (!raw_key.equals(current_key)) {
String rename = MessageText.getString(current_key, "");
if (rename.length() > 0) {
name += " (->" + rename + ")";
}
}
GCStringPrinter sp = new GCStringPrinter(gc, name, bounds, GCStringPrinter.FLAG_SKIPCLIP, SWT.TOP);
sp.printString();
Point titleSize = sp.getCalculatedSize();
gc.setFont(fontDefault);
String info = MessageText.getString(raw_key + ".info", "");
Rectangle infoBounds = new Rectangle(bounds.x + 10, bounds.y + titleSize.y + 5, bounds.width - 15, bounds.height - 20);
GCStringPrinter.printString(gc, info, infoBounds, true, false);
TableColumnInfo columnInfo = (TableColumnInfo) cell.getTableRow().getData("columninfo");
if (columnInfo == null) {
final TableColumnManager tcm = TableColumnManager.getInstance();
columnInfo = tcm.getColumnInfo(column.getForDataSourceType(), column.getTableID(), column.getName());
cell.getTableRowCore().setData("columninfo", columnInfo);
}
Rectangle profBounds = new Rectangle(bounds.width - 100, bounds.y - 2, 100, 20);
byte proficiency = columnInfo.getProficiency();
if (proficiency > 0 && proficiency < profText.length) {
int alpha = gc.getAlpha();
gc.setAlpha(0xA0);
GCStringPrinter.printString(gc, MessageText.getString("ConfigView.section.mode." + profText[proficiency]), profBounds, true, false, SWT.RIGHT | SWT.TOP);
gc.setAlpha(alpha);
}
Rectangle hitArea;
TableView<?> tv = ((TableCellCore) cell).getTableRowCore().getView();
TableColumnSetupWindow tvs = (TableColumnSetupWindow) tv.getParentDataSource();
if (tvs.isColumnAdded(column)) {
hitArea = Utils.EMPTY_RECT;
} else {
int x = bounds.x + titleSize.x + 15;
int y = bounds.y - 1;
int h = 15;
String textAdd = MessageText.getString("Button.add");
GCStringPrinter sp2 = new GCStringPrinter(gc, textAdd, new Rectangle(x, y, 500, h), true, false, SWT.CENTER);
sp2.calculateMetrics();
int w = sp2.getCalculatedSize().x + 12;
gc.setAdvanced(true);
gc.setAntialias(SWT.ON);
gc.setBackground(ColorCache.getColor(gc.getDevice(), 255, 255, 255));
gc.fillRoundRectangle(x, y, w, h, 15, h);
gc.setBackground(ColorCache.getColor(gc.getDevice(), 215, 215, 215));
gc.fillRoundRectangle(x + 2, y + 2, w, h, 15, h);
gc.setForeground(ColorCache.getColor(gc.getDevice(), 145, 145, 145));
gc.drawRoundRectangle(x, y, w, h, 15, h);
gc.setForeground(ColorCache.getColor(gc.getDevice(), 50, 50, 50));
hitArea = new Rectangle(x, y, w + 2, h);
sp2.printString(gc, hitArea, SWT.CENTER);
bounds = cell.getBounds();
hitArea.x -= bounds.x;
hitArea.y -= bounds.y;
}
cell.getTableRowCore().setData("AddHitArea", hitArea);
}
use of com.biglybt.ui.common.table.impl.TableColumnManager in project BiglyBT by BiglySoftware.
the class TableColumnSetupWindow method apply.
/**
* @since 4.0.0.5
*/
protected void apply() {
TableColumnManager tcm = TableColumnManager.getInstance();
if (doReset) {
TableColumnCore[] allTableColumns = tcm.getAllTableColumnCoreAsArray(forDataSourceType, forTableID);
if (allTableColumns != null) {
for (TableColumnCore column : allTableColumns) {
if (column != null) {
column.reset();
}
}
}
}
for (TableColumnCore tc : mapNewVisibility.keySet()) {
boolean visible = mapNewVisibility.get(tc).booleanValue();
tc.setVisible(visible);
}
tcm.saveTableColumns(forDataSourceType, forTableID);
listener.tableStructureChanged(true, forDataSourceType);
}
use of com.biglybt.ui.common.table.impl.TableColumnManager in project BiglyBT by BiglySoftware.
the class TableColumnSetupWindow method createTVChosen.
/**
* @return
*
* @since 4.0.0.5
*/
private TableViewSWT<?> createTVChosen() {
final TableColumnManager tcm = TableColumnManager.getInstance();
TableColumnCore[] columnTVChosen = tcm.getAllTableColumnCoreAsArray(TableColumn.class, TABLEID_CHOSEN);
for (int i = 0; i < columnTVChosen.length; i++) {
TableColumnCore column = columnTVChosen[i];
if (column.getName().equals(ColumnTC_ChosenColumn.COLUMN_ID)) {
column.setVisible(true);
column.setWidth(175);
column.setSortAscending(true);
} else {
column.setVisible(false);
}
}
final TableViewSWT<?> tvChosen = TableViewFactory.createTableViewSWT(TableColumn.class, TABLEID_CHOSEN, TABLEID_CHOSEN, columnTVChosen, ColumnTC_ChosenColumn.COLUMN_ID, SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.MULTI);
tvAvail.setParentDataSource(this);
tvChosen.setMenuEnabled(false);
tvChosen.setHeaderVisible(false);
// tvChosen.setRowDefaultHeight(16);
tvChosen.addLifeCycleListener(new TableLifeCycleListener() {
private DragSource dragSource;
private DropTarget dropTarget;
@Override
public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
switch(eventType) {
case EVENT_TABLELIFECYCLE_INITIALIZED:
tableViewInitialized();
break;
case EVENT_TABLELIFECYCLE_DESTROYED:
tableViewDestroyed();
break;
}
}
private void tableViewInitialized() {
dragSource = tvChosen.createDragSource(DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
dragSource.setTransfer(new Transfer[] { TextTransfer.getInstance() });
dragSource.setData("tv", tvChosen);
dragSource.addDragListener(dragSourceListener);
dropTarget = tvChosen.createDropTarget(DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_TARGET_MOVE);
dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
dropTarget.addDropListener(new DropTargetListener() {
@Override
public void dropAccept(DropTargetEvent event) {
// TODO Auto-generated method stub
}
@Override
public void drop(DropTargetEvent event) {
String id = (String) event.data;
TableRowCore destRow = tvChosen.getRow(event);
TableView<?> tv = id.equals("c") ? tvChosen : tvAvail;
Object[] dataSources = tv.getSelectedDataSources().toArray();
for (int i = 0; i < dataSources.length; i++) {
TableColumnCore column = (TableColumnCore) dataSources[i];
if (column != null) {
chooseColumn(column, destRow, true);
TableRowCore row = tvAvail.getRow(column);
if (row != null) {
row.redraw();
}
}
}
}
@Override
public void dragOver(DropTargetEvent event) {
// TODO Auto-generated method stub
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
// TODO Auto-generated method stub
}
@Override
public void dragLeave(DropTargetEvent event) {
// TODO Auto-generated method stub
}
@Override
public void dragEnter(DropTargetEvent event) {
// TODO Auto-generated method stub
}
});
}
private void tableViewDestroyed() {
if (dragSource != null && !dragSource.isDisposed()) {
dragSource.dispose();
}
if (dropTarget != null && !dropTarget.isDisposed()) {
dropTarget.dispose();
}
}
});
tvChosen.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.stateMask == 0 && (e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.DEL)) {
removeSelectedChosen();
e.doit = false;
}
if (e.stateMask == SWT.CONTROL) {
if (e.keyCode == SWT.ARROW_UP) {
moveChosenUp();
e.doit = false;
} else if (e.keyCode == SWT.ARROW_DOWN) {
moveChosenDown();
e.doit = false;
}
}
}
});
return tvChosen;
}
use of com.biglybt.ui.common.table.impl.TableColumnManager in project BiglyBT by BiglySoftware.
the class TableViewSWT_Common method fillColumnMenu.
/**
* SubMenu for column specific tasks.
*
* @param iColumn Column # that tasks apply to.
*/
public void fillColumnMenu(final Menu menu, final TableColumnCore column, boolean isBlankArea) {
String tableID = tv.getTableID();
int hiddenColumnCount = 0;
if (!isBlankArea) {
TableColumnManager tcm = TableColumnManager.getInstance();
TableColumnCore[] allTableColumns = tcm.getAllTableColumnCoreAsArray(tv.getDataSourceType(), tableID);
Arrays.sort(allTableColumns, TableColumnManager.getTableColumnOrderComparator());
for (final TableColumnCore tc : allTableColumns) {
boolean visible = tc.isVisible();
if (!visible) {
TableColumnInfo columnInfo = tcm.getColumnInfo(tv.getDataSourceType(), tableID, tc.getName());
if (columnInfo.getProficiency() != TableColumnInfo.PROFICIENCY_BEGINNER) {
hiddenColumnCount++;
continue;
}
}
MenuItem menuItem = new MenuItem(menu, SWT.CHECK);
Messages.setLanguageText(menuItem, tc.getTitleLanguageKey());
if (visible) {
menuItem.setSelection(true);
}
menuItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
tc.setVisible(!tc.isVisible());
TableColumnManager tcm = TableColumnManager.getInstance();
String tableID = tv.getTableID();
tcm.saveTableColumns(tv.getDataSourceType(), tableID);
if (tv instanceof TableStructureModificationListener) {
((TableStructureModificationListener) tv).tableStructureChanged(true, null);
}
TableStructureEventDispatcher.getInstance(tableID).tableStructureChanged(true, null);
}
});
}
}
if (hiddenColumnCount > 0) {
MenuItem itemMoreHidden = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemMoreHidden, "MyTorrentsView.menu.moreColHidden", new String[] { String.valueOf(hiddenColumnCount) });
itemMoreHidden.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
showColumnEditor();
}
});
}
if (menu.getItemCount() > 0) {
new MenuItem(menu, SWT.SEPARATOR);
}
if (column != null) {
final MenuItem renameColumn = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(renameColumn, "MyTorrentsView.menu.renameColumn");
renameColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("ColumnRenameWindow.title", "ColumnRenameWindow.message");
String existing_name = column.getNameOverride();
if (existing_name == null) {
existing_name = "";
}
entryWindow.setPreenteredText(existing_name, false);
entryWindow.selectPreenteredText(true);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
String name = entryWindow.getSubmittedInput().trim();
if (name.length() == 0) {
name = null;
}
column.setNameOverride(name);
TableColumnManager tcm = TableColumnManager.getInstance();
String tableID = tv.getTableID();
tcm.saveTableColumns(tv.getDataSourceType(), tableID);
TableStructureEventDispatcher.getInstance(tableID).tableStructureChanged(true, null);
}
});
}
});
final MenuItem itemPrefSize = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemPrefSize, "table.columns.pref.size");
itemPrefSize.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
column.setPreferredWidth(-1);
tv.runForAllRows(new TableGroupRowRunner() {
@Override
public void run(TableRowCore row) {
row.fakeRedraw(column.getName());
}
});
int pref = column.getPreferredWidth();
if (pref != -1) {
column.setWidth(pref);
}
}
});
}
});
}
final MenuItem itemResetColumns = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemResetColumns, "table.columns.reset");
itemResetColumns.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
String tableID = tv.getTableID();
TableColumnManager tcm = TableColumnManager.getInstance();
tcm.resetColumns(tv.getDataSourceType(), tableID);
}
});
final MenuItem itemChangeTable = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemChangeTable, "MyTorrentsView.menu.editTableColumns");
Utils.setMenuItemImage(itemChangeTable, "columns");
itemChangeTable.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
showColumnEditor();
}
});
menu.setData("column", column);
if (column == null) {
return;
}
String sColumnName = column.getName();
if (sColumnName != null) {
Object[] listeners = listenersMenuFill.toArray();
for (int i = 0; i < listeners.length; i++) {
TableViewSWTMenuFillListener l = (TableViewSWTMenuFillListener) listeners[i];
l.addThisColumnSubMenu(sColumnName, menu);
}
}
final MenuItem at_item = new MenuItem(menu, SWT.CHECK);
Messages.setLanguageText(at_item, "MyTorrentsView.menu.thisColumn.autoTooltip");
at_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
TableColumnCore tcc = (TableColumnCore) menu.getData("column");
tcc.setAutoTooltip(at_item.getSelection());
tcc.invalidateCells();
}
});
at_item.setSelection(column.doesAutoTooltip());
at_item.setEnabled(!TableTooltips.tooltips_disabled);
// Add Plugin Context menus..
TableContextMenuItem[] items = column.getContextMenuItems(TableColumnCore.MENU_STYLE_HEADER);
if (items.length > 0) {
new MenuItem(menu, SWT.SEPARATOR);
MenuBuildUtils.addPluginMenuItems(items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(tv.getSelectedDataSources(true)));
}
}
Aggregations