use of com.biglybt.ui.swt.pif.UISWTInstance in project BiglyBT by BiglySoftware.
the class TableViewSWT_TabsCommon method buildFolder.
private void buildFolder(final Composite form, final String props_prefix) {
PluginInterface pi = PluginInitializer.getDefaultInterface();
UIManager uim = pi.getUIManager();
MenuManager menuManager = uim.getMenuManager();
menuItemShowTabs = menuManager.addMenuItem(props_prefix + "._end_", "ConfigView.section.style.ShowTabsInTorrentView");
menuItemShowTabs.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItemShowTabs.setStyle(MenuItem.STYLE_CHECK);
menuItemShowTabs.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.setData(COConfigurationManager.getBooleanParameter("Library.ShowTabsInTorrentView"));
}
});
menuItemShowTabs.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
COConfigurationManager.setParameter("Library.ShowTabsInTorrentView", (Boolean) menu.getData());
}
});
cTabsHolder.addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event e) {
if (tabbedMDI.getMinimized()) {
fdHeightChanger.height = tabbedMDI.getFolderHeight();
cTabsHolder.getParent().layout();
return;
}
Double l = (Double) sash.getData("PCT");
if (l != null) {
int newHeight = (int) (form.getBounds().height * l.doubleValue());
if (newHeight != fdHeightChanger.height) {
fdHeightChanger.height = newHeight;
cTabsHolder.getParent().layout();
}
}
}
});
String[] restricted_to = tv.getTabViewsRestrictedTo();
Set<String> rt_set = new HashSet<>();
if (restricted_to != null) {
rt_set.addAll(Arrays.asList(restricted_to));
}
// Call plugin listeners
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
if (pluginUI != null) {
UISWTViewEventListenerWrapper[] pluginViews = pluginUI.getViewListeners(tv.getTableID());
if (pluginViews != null) {
for (final UISWTViewEventListenerWrapper l : pluginViews) {
if (l == null) {
continue;
}
try {
String view_id = l.getViewID();
if (restricted_to != null && !rt_set.contains(view_id)) {
continue;
}
tabbedMDI.registerEntry(view_id, new MdiEntryCreationListener2() {
@Override
public MdiEntry createMDiEntry(MultipleDocumentInterface mdi, String id, Object datasource, Map<?, ?> params) {
return addTabView(l, null);
}
});
tabbedMDI.loadEntryByID(view_id, false);
} catch (Exception e) {
// skip, plugin probably specifically asked to not be added
}
}
}
}
}
if (!tabbedMDI.getMinimized()) {
MdiEntry[] entries = tabbedMDI.getEntries();
if (entries.length > 0) {
tabbedMDI.showEntry(entries[0]);
}
}
}
use of com.biglybt.ui.swt.pif.UISWTInstance in project BiglyBT by BiglySoftware.
the class TableViewSWT_TabsCommon method createSashForm.
public Composite createSashForm(final Composite composite) {
if (!tv.isTabViewsEnabled()) {
tableComposite = tv.createMainPanel(composite);
return tableComposite;
}
SelectedContentManager.addCurrentlySelectedContentListener(this);
ConfigurationManager configMan = ConfigurationManager.getInstance();
int iNumViews = 0;
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
if (pluginUI != null) {
iNumViews += pluginUI.getViewListeners(tv.getTableID()).length;
}
}
if (iNumViews == 0) {
tableComposite = tv.createMainPanel(composite);
return tableComposite;
}
final String props_prefix = tv.getTableID() + "." + tv.getPropertiesPrefix();
FormData formData;
final Composite form = new Composite(composite, SWT.NONE);
FormLayout flayout = new FormLayout();
flayout.marginHeight = 0;
flayout.marginWidth = 0;
form.setLayout(flayout);
GridData gridData;
gridData = new GridData(GridData.FILL_BOTH);
form.setLayoutData(gridData);
// Create them in reverse order, so we can have the table auto-grow, and
// set the tabFolder's height manually
cTabsHolder = new Composite(form, SWT.NONE);
tabbedMDI = uiFunctions.createTabbedMDI(cTabsHolder, props_prefix);
tabbedMDI.setMaximizeVisible(true);
tabbedMDI.setMinimizeVisible(true);
tabbedMDI.setTabbedMdiMaximizeListener(new TabbedMdiMaximizeListener() {
@Override
public void maximizePressed() {
TableView tvToUse = tvOverride == null ? tv : tvOverride;
Object[] ds = tvToUse.getSelectedDataSources(true);
if (ds.length == 1 && ds[0] instanceof DownloadManager) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, ds);
}
}
}
});
final int SASH_WIDTH = 5;
sash = Utils.createSash(form, SASH_WIDTH);
tableComposite = tv.createMainPanel(form);
Composite cFixLayout = tableComposite;
while (cFixLayout != null && cFixLayout.getParent() != form) {
cFixLayout = cFixLayout.getParent();
}
if (cFixLayout == null) {
cFixLayout = tableComposite;
}
GridLayout layout = new GridLayout();
layout.numColumns = 1;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
cFixLayout.setLayout(layout);
// FormData for Folder
formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.bottom = new FormAttachment(100, 0);
int iSplitAt = configMan.getIntParameter(props_prefix + ".SplitAt", 3000);
// Was stored at whole
if (iSplitAt < 100) {
iSplitAt *= 100;
}
// pct is % bottom
double pct = iSplitAt / 10000.0;
if (pct < 0.03) {
pct = 0.03;
} else if (pct > 0.97) {
pct = 0.97;
}
// height will be set on first resize call
sash.setData("PCT", new Double(pct));
cTabsHolder.setLayout(new FormLayout());
fdHeightChanger = formData;
cTabsHolder.setLayoutData(formData);
// FormData for Sash
formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.bottom = new FormAttachment(cTabsHolder);
formData.height = SASH_WIDTH;
sash.setLayoutData(formData);
// FormData for table Composite
formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.top = new FormAttachment(0, 0);
formData.bottom = new FormAttachment(sash);
cFixLayout.setLayoutData(formData);
// Listeners to size the folder
sash.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final boolean FASTDRAG = true;
if (FASTDRAG && e.detail == SWT.DRAG) {
return;
}
Rectangle area = form.getClientArea();
int height = area.height - e.y - e.height;
if (!Constants.isWindows) {
height -= SASH_WIDTH;
}
if (area.height - height < 100) {
height = area.height - 100;
}
if (height < 0) {
height = 0;
}
fdHeightChanger.height = height;
Double l = new Double((double) height / area.height);
sash.setData("PCT", l);
if (e.detail != SWT.DRAG) {
ConfigurationManager configMan = ConfigurationManager.getInstance();
configMan.setParameter(props_prefix + ".SplitAt", (int) (l.doubleValue() * 10000));
}
form.layout();
// sometimes sash cheese is left
cTabsHolder.redraw();
}
});
buildFolder(form, props_prefix);
return form;
}
use of com.biglybt.ui.swt.pif.UISWTInstance in project BiglyBT by BiglySoftware.
the class BaseMDI method skinObjectInitialShow.
@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
final UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
ui_manager.addUIListener(new UIManagerListener() {
@Override
public void UIDetached(UIInstance instance) {
}
@Override
public void UIAttached(UIInstance instance) {
if (instance instanceof UISWTInstance) {
ui_manager.removeUIListener(this);
final AESemaphore wait_sem = new AESemaphore("SideBar:wait");
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
try {
try {
loadCloseables();
} catch (Throwable t) {
Debug.out(t);
}
setupPluginViews();
} finally {
wait_sem.release();
}
}
});
if (!wait_sem.reserve(10 * 1000)) {
Debug.out("eh?");
}
}
}
});
return null;
}
use of com.biglybt.ui.swt.pif.UISWTInstance in project BiglyBT by BiglySoftware.
the class FilesView method initYourTableView.
@Override
public TableViewSWT<DiskManagerFileInfo> initYourTableView() {
tv = TableViewFactory.createTableViewSWT(com.biglybt.pif.disk.DiskManagerFileInfo.class, TableManager.TABLE_TORRENT_FILES, getPropertiesPrefix(), basicItems, "firstpiece", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
if (allowTabViews) {
tv.setEnableTabViews(enable_tabs, true, null);
}
basicItems = new TableColumnCore[0];
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
registerPluginViews(pluginUI);
}
tv.addTableDataSourceChangedListener(this, true);
tv.addRefreshListener(this, true);
tv.addSelectionListener(this, false);
tv.addMenuFillListener(this);
tv.addLifeCycleListener(this);
tv.addKeyListener(this);
tv.addRefreshListener(new TableRowRefreshListener() {
@Override
public void rowRefresh(TableRow row) {
if (row instanceof TableRowSWT) {
Object ds = ((TableRowSWT) row).getDataSource(true);
if (ds instanceof FilesViewNodeInner) {
((TableRowSWT) row).setFontStyle(SWT.ITALIC);
((TableRowSWT) row).setAlpha(220);
}
}
}
});
return tv;
}
use of com.biglybt.ui.swt.pif.UISWTInstance in project BiglyBT by BiglySoftware.
the class TrackerView method initYourTableView.
@Override
public TableViewSWT<TrackerPeerSource> initYourTableView() {
tv = TableViewFactory.createTableViewSWT(TrackerPeerSource.class, TableManager.TABLE_TORRENT_TRACKERS, getPropertiesPrefix(), basicItems, basicItems[0].getName(), SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
tv.addLifeCycleListener(this);
tv.addMenuFillListener(this);
tv.addTableDataSourceChangedListener(this, true);
tv.addSelectionListener(this, false);
tv.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
Object[] datasources = tv.getSelectedDataSources().toArray();
List<TrackerPeerSource> pss = new ArrayList<>();
String str = "";
for (Object object : datasources) {
TrackerPeerSource ps = (TrackerPeerSource) object;
if (ps.canDelete()) {
pss.add(ps);
str += (str.isEmpty() ? "" : ", ") + ps.getName();
}
}
if (!pss.isEmpty()) {
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { str }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == 0) {
for (TrackerPeerSource ps : pss) {
ps.delete();
}
}
}
});
}
e.doit = false;
}
}
});
tv.setEnableTabViews(enable_tabs, true, null);
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
registerPluginViews(pluginUI);
}
return tv;
}
Aggregations