use of com.biglybt.pif.ui.model.BasicPluginConfigModel in project BiglyBT by BiglySoftware.
the class BasicPluginConfigImpl method maxUserMode.
@Override
public int maxUserMode() {
BasicPluginConfigModel model = model_ref.get();
int max_mode = 0;
if (model != null) {
com.biglybt.pif.ui.config.Parameter[] parameters = model.getParameters();
for (int i = 0; i < parameters.length; i++) {
ParameterImpl param = (ParameterImpl) parameters[i];
if (param.getMinimumRequiredUserMode() > max_mode) {
max_mode = param.getMinimumRequiredUserMode();
}
}
}
return (max_mode);
}
use of com.biglybt.pif.ui.model.BasicPluginConfigModel in project BiglyBT by BiglySoftware.
the class UISWTInstanceImpl method eventOccurred.
@Override
public boolean eventOccurred(final UIManagerEvent event) {
boolean done = true;
final Object data = event.getData();
switch(event.getType()) {
case UIManagerEvent.ET_SHOW_TEXT_MESSAGE:
{
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
String[] params = (String[]) data;
new TextViewerWindow(params[0], params[1], params[2]);
}
});
break;
}
case UIManagerEvent.ET_SHOW_MSG_BOX:
{
final int[] result = { UIManagerEvent.MT_NONE };
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
UIFunctionsManagerSWT.getUIFunctionsSWT().bringToFront();
Object[] params = (Object[]) data;
long _styles = ((Long) (params[2])).longValue();
int styles = 0;
int def = 0;
if ((_styles & UIManagerEvent.MT_YES) != 0) {
styles |= SWT.YES;
}
if ((_styles & UIManagerEvent.MT_YES_DEFAULT) != 0) {
styles |= SWT.YES;
def = SWT.YES;
}
if ((_styles & UIManagerEvent.MT_NO) != 0) {
styles |= SWT.NO;
}
if ((_styles & UIManagerEvent.MT_NO_DEFAULT) != 0) {
styles |= SWT.NO;
def = SWT.NO;
}
if ((_styles & UIManagerEvent.MT_OK) != 0) {
styles |= SWT.OK;
}
if ((_styles & UIManagerEvent.MT_OK_DEFAULT) != 0) {
styles |= SWT.OK;
def = SWT.OK;
}
if ((_styles & UIManagerEvent.MT_CANCEL) != 0) {
styles |= SWT.CANCEL;
}
MessageBoxShell mb = new MessageBoxShell(styles, MessageText.getString((String) params[0]), MessageText.getString((String) params[1]));
if (def != 0) {
mb.setDefaultButtonUsingStyle(def);
}
if (params.length == 4 && params[3] instanceof Map) {
Map<String, Object> options = (Map<String, Object>) params[3];
String rememberID = (String) options.get(UIManager.MB_PARAM_REMEMBER_ID);
Boolean rememberByDefault = (Boolean) options.get(UIManager.MB_PARAM_REMEMBER_BY_DEF);
String rememberText = (String) options.get(UIManager.MB_PARAM_REMEMBER_RES);
if (rememberID != null && rememberByDefault != null && rememberText != null) {
mb.setRemember(rememberID, rememberByDefault, rememberText);
Number rememberIfOnlyButton = (Number) options.get(UIManager.MB_PARAM_REMEMBER_IF_ONLY_BUTTON);
if (rememberIfOnlyButton != null) {
mb.setRememberOnlyIfButton(rememberIfOnlyButton.intValue());
}
}
Number auto_close_ms = (Number) options.get(UIManager.MB_PARAM_AUTO_CLOSE_MS);
if (auto_close_ms != null) {
mb.setAutoCloseInMS(auto_close_ms.intValue());
}
} else if (params.length >= 6) {
String rememberID = (String) params[3];
Boolean rememberByDefault = (Boolean) params[4];
String rememberText = (String) params[5];
if (rememberID != null && rememberByDefault != null && rememberText != null) {
mb.setRemember(rememberID, rememberByDefault, rememberText);
}
}
mb.open(null);
int _r = mb.waitUntilClosed();
int r = 0;
if ((_r & SWT.YES) != 0) {
r |= UIManagerEvent.MT_YES;
}
if ((_r & SWT.NO) != 0) {
r |= UIManagerEvent.MT_NO;
}
if ((_r & SWT.OK) != 0) {
r |= UIManagerEvent.MT_OK;
}
if ((_r & SWT.CANCEL) != 0) {
r |= UIManagerEvent.MT_CANCEL;
}
result[0] = r;
}
}, false);
event.setResult(new Long(result[0]));
break;
}
case UIManagerEvent.ET_OPEN_TORRENT_VIA_FILE:
{
TorrentOpener.openTorrent(((File) data).toString());
break;
}
case UIManagerEvent.ET_OPEN_TORRENT_VIA_TORRENT:
{
Torrent t = (Torrent) data;
try {
File f = AETemporaryFileHandler.createTempFile();
t.writeToFile(f);
TorrentOpener.openTorrent(f.toString());
} catch (Throwable e) {
Debug.printStackTrace(e);
}
break;
}
case UIManagerEvent.ET_OPEN_TORRENT_VIA_URL:
{
Display display = Utils.getDisplay();
display.syncExec(new AERunnable() {
@Override
public void runSupport() {
Object[] params = (Object[]) data;
URL target = (URL) params[0];
URL referrer = (URL) params[1];
boolean auto_download = ((Boolean) params[2]).booleanValue();
Map<?, ?> request_properties = (Map<?, ?>) params[3];
if (auto_download) {
final Shell shell = uiFunctions.getMainShell();
if (shell != null) {
final List<String> alt_uris = new ArrayList<>();
if (request_properties != null) {
request_properties = new HashMap(request_properties);
for (int i = 1; i < 16; i++) {
String key = "X-Alternative-URI-" + i;
String uri = (String) request_properties.remove(key);
if (uri != null) {
alt_uris.add(uri);
} else {
break;
}
}
}
final Map<?, ?> f_request_properties = request_properties;
new FileDownloadWindow(shell, target.toString(), referrer == null ? null : referrer.toString(), request_properties, new Runnable() {
int alt_index = 0;
@Override
public void run() {
if (alt_index < alt_uris.size()) {
String alt_target = alt_uris.get(alt_index++);
new FileDownloadWindow(shell, alt_target, null, f_request_properties, this);
}
}
});
}
} else {
// TODO: handle referrer?
TorrentOpener.openTorrent(target.toString());
}
}
});
break;
}
case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_CREATED:
{
if (data instanceof BasicPluginViewModel) {
BasicPluginViewModel model = (BasicPluginViewModel) data;
// property bundles can't handle spaces in keys
//
// If this behaviour changes, change the openView(model)
// method lower down.
String sViewID = model.getName().replaceAll(" ", ".");
BasicPluginViewImpl view = new BasicPluginViewImpl(model);
addView(UISWTInstance.VIEW_MAIN, sViewID, view);
}
break;
}
case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_DESTROYED:
{
if (data instanceof BasicPluginViewModel) {
BasicPluginViewModel model = (BasicPluginViewModel) data;
// property bundles can't handle spaces in keys
//
// If this behaviour changes, change the openView(model)
// method lower down.
String sViewID = model.getName().replaceAll(" ", ".");
removeViews(UISWTInstance.VIEW_MAIN, sViewID);
}
break;
}
case UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_CREATED:
{
if (data instanceof BasicPluginConfigModel) {
BasicPluginConfigModel model = (BasicPluginConfigModel) data;
BasicPluginConfigImpl view = new BasicPluginConfigImpl(new WeakReference<>(model));
config_view_map.put(model, view);
ConfigSectionRepository.getInstance().addConfigSection(view, model.getPluginInterface());
}
break;
}
case UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_DESTROYED:
{
if (data instanceof BasicPluginConfigModel) {
BasicPluginConfigModel model = (BasicPluginConfigModel) data;
BasicPluginConfigImpl view = config_view_map.get(model);
if (view != null) {
ConfigSectionRepository.getInstance().removeConfigSection(view);
}
}
break;
}
case UIManagerEvent.ET_COPY_TO_CLIPBOARD:
{
ClipboardCopy.copyToClipBoard((String) data);
break;
}
case UIManagerEvent.ET_OPEN_URL:
{
Utils.launch(((URL) data).toExternalForm());
break;
}
case UIManagerEvent.ET_SHOW_CONFIG_SECTION:
{
event.setResult(Boolean.FALSE);
if (!(data instanceof String)) {
break;
}
event.setResult(Boolean.TRUE);
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, data);
break;
}
case UIManagerEvent.ET_FILE_OPEN:
{
File file_to_use = (File) data;
Utils.launch(file_to_use.getAbsolutePath());
break;
}
case UIManagerEvent.ET_FILE_SHOW:
{
File file_to_use = (File) data;
final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
ManagerUtils.open(file_to_use, use_open_containing_folder);
break;
}
case UIManagerEvent.ET_HIDE_ALL:
{
boolean hide = (Boolean) data;
uiFunctions.setHideAll(hide);
break;
}
case UIManagerEvent.ET_HIDE_ALL_TOGGLE:
{
uiFunctions.setHideAll(!uiFunctions.getHideAll());
break;
}
default:
{
done = false;
break;
}
}
return (done);
}
use of com.biglybt.pif.ui.model.BasicPluginConfigModel in project BiglyBT by BiglySoftware.
the class ConfigSectionPlugins method configSectionCreate.
@Override
public Composite configSectionCreate(final Composite parent) {
if (!CoreFactory.isCoreRunning()) {
Composite cSection = new Composite(parent, SWT.NULL);
cSection.setLayout(new FillLayout());
Label lblNotAvail = new Label(cSection, SWT.WRAP);
Messages.setLanguageText(lblNotAvail, "core.not.available");
return cSection;
}
GridLayout layout;
GridData gridData;
Label label;
ImageLoader imageLoader = ImageLoader.getInstance();
imgRedLed = imageLoader.getImage("redled");
imgGreenLed = imageLoader.getImage("greenled");
Composite infoGroup = new Composite(parent, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
Utils.setLayoutData(infoGroup, gridData);
layout = new GridLayout();
layout.numColumns = 1;
layout.marginWidth = 0;
layout.marginHeight = 0;
infoGroup.setLayout(layout);
infoGroup.setLayout(new GridLayout());
String sep = System.getProperty("file.separator");
File fUserPluginDir = FileUtil.getUserFile("plugins");
String sUserPluginDir;
try {
sUserPluginDir = fUserPluginDir.getCanonicalPath();
} catch (Throwable e) {
sUserPluginDir = fUserPluginDir.toString();
}
if (!sUserPluginDir.endsWith(sep)) {
sUserPluginDir += sep;
}
File fAppPluginDir = FileUtil.getApplicationFile("plugins");
String sAppPluginDir;
try {
sAppPluginDir = fAppPluginDir.getCanonicalPath();
} catch (Throwable e) {
sAppPluginDir = fAppPluginDir.toString();
}
if (!sAppPluginDir.endsWith(sep)) {
sAppPluginDir += sep;
}
label = new Label(infoGroup, SWT.WRAP);
Utils.setLayoutData(label, new GridData(GridData.FILL_HORIZONTAL));
Messages.setLanguageText(label, "ConfigView.pluginlist.whereToPut");
label = new Label(infoGroup, SWT.WRAP);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalIndent = 10;
Utils.setLayoutData(label, gridData);
label.setText(sUserPluginDir.replaceAll("&", "&&"));
label.setForeground(Colors.blue);
label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
final String _sUserPluginDir = sUserPluginDir;
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent arg0) {
if (_sUserPluginDir.endsWith("/plugins/") || _sUserPluginDir.endsWith("\\plugins\\")) {
File f = new File(_sUserPluginDir);
String dir = _sUserPluginDir;
if (!(f.exists() && f.isDirectory())) {
dir = _sUserPluginDir.substring(0, _sUserPluginDir.length() - 9);
}
Utils.launch(dir);
}
}
});
label = new Label(infoGroup, SWT.WRAP);
Utils.setLayoutData(label, new GridData(GridData.FILL_HORIZONTAL));
Messages.setLanguageText(label, "ConfigView.pluginlist.whereToPutOr");
label = new Label(infoGroup, SWT.WRAP);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalIndent = 10;
Utils.setLayoutData(label, gridData);
label.setText(sAppPluginDir.replaceAll("&", "&&"));
label.setForeground(Colors.blue);
label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
final String _sAppPluginDir = sAppPluginDir;
// TODO : Fix it for windows
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent arg0) {
if (_sAppPluginDir.endsWith("/plugins/") || _sAppPluginDir.endsWith("\\plugins\\")) {
File f = new File(_sAppPluginDir);
if (f.exists() && f.isDirectory()) {
Utils.launch(_sAppPluginDir);
} else {
String appDir = _sAppPluginDir.substring(0, _sAppPluginDir.length() - 9);
System.out.println(appDir);
Utils.launch(appDir);
}
}
}
});
pluginIFs = rebuildPluginIFs();
Collections.sort(pluginIFs, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
return (((PluginInterface) o1).getPluginName().compareToIgnoreCase(((PluginInterface) o2).getPluginName()));
}
});
Label labelInfo = new Label(infoGroup, SWT.WRAP);
Utils.setLayoutData(labelInfo, new GridData(GridData.FILL_HORIZONTAL));
Messages.setLanguageText(labelInfo, "ConfigView.pluginlist.info");
table = new Table(infoGroup, SWT.BORDER | SWT.SINGLE | SWT.CHECK | SWT.VIRTUAL | SWT.FULL_SELECTION);
gridData = new GridData(GridData.FILL_BOTH);
gridData.heightHint = 200;
gridData.widthHint = 200;
Utils.setLayoutData(table, gridData);
for (int i = 0; i < COLUMN_HEADERS.length; i++) {
final TableColumn tc = new TableColumn(table, COLUMN_ALIGNS[i]);
tc.setWidth(Utils.adjustPXForDPI(COLUMN_SIZES[i]));
tc.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean ascending = comparator.setField(table.indexOf(tc));
try {
table.setSortColumn(tc);
table.setSortDirection(ascending ? SWT.UP : SWT.DOWN);
} catch (NoSuchMethodError ignore) {
// Ignore Pre 3.0
}
Collections.sort(pluginIFs, comparator);
table.clearAll();
}
});
Messages.setLanguageText(tc, HEADER_PREFIX + COLUMN_HEADERS[i]);
}
table.setHeaderVisible(true);
Composite cButtons = new Composite(infoGroup, SWT.NONE);
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 5;
cButtons.setLayout(layout);
Utils.setLayoutData(cButtons, new GridData());
final Button btnUnload = new Button(cButtons, SWT.PUSH);
Utils.setLayoutData(btnUnload, new GridData());
Messages.setLanguageText(btnUnload, "ConfigView.pluginlist.unloadSelected");
btnUnload.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final int[] items = table.getSelectionIndices();
new AEThread2("unload") {
@Override
public void run() {
for (int i = 0; i < items.length; i++) {
int index = items[i];
if (index >= 0 && index < pluginIFs.size()) {
PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
if (pluginIF.getPluginState().isOperational()) {
if (pluginIF.getPluginState().isUnloadable()) {
try {
pluginIF.getPluginState().unload();
} catch (PluginException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
pluginIFs = rebuildPluginIFs();
table.setItemCount(pluginIFs.size());
Collections.sort(pluginIFs, comparator);
table.clearAll();
}
});
}
}
}
}.start();
}
});
btnUnload.setEnabled(false);
final Button btnLoad = new Button(cButtons, SWT.PUSH);
Utils.setLayoutData(btnUnload, new GridData());
Messages.setLanguageText(btnLoad, "ConfigView.pluginlist.loadSelected");
btnLoad.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final int[] items = table.getSelectionIndices();
new AEThread2("load") {
@Override
public void run() {
for (int i = 0; i < items.length; i++) {
int index = items[i];
if (index >= 0 && index < pluginIFs.size()) {
PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
// Already loaded.
if (pluginIF.getPluginState().isOperational()) {
continue;
}
// initialise.
if (pluginIF.getPluginState().isDisabled()) {
if (pluginIF.getPluginState().hasFailed()) {
continue;
}
pluginIF.getPluginState().setDisabled(false);
}
try {
pluginIF.getPluginState().reload();
} catch (PluginException e1) {
// TODO Auto-generated catch block
Debug.printStackTrace(e1);
}
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (table == null || table.isDisposed()) {
return;
}
pluginIFs = rebuildPluginIFs();
table.setItemCount(pluginIFs.size());
Collections.sort(pluginIFs, comparator);
table.clearAll();
}
});
}
}
}
}.start();
}
});
btnLoad.setEnabled(false);
// scan
final Button btnScan = new Button(cButtons, SWT.PUSH);
Utils.setLayoutData(btnScan, new GridData());
Messages.setLanguageText(btnScan, "ConfigView.pluginlist.scan");
btnScan.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CoreFactory.getSingleton().getPluginManager().refreshPluginList(false);
pluginIFs = rebuildPluginIFs();
table.setItemCount(pluginIFs.size());
Collections.sort(pluginIFs, comparator);
table.clearAll();
}
});
// uninstall
final Button btnUninstall = new Button(cButtons, SWT.PUSH);
Utils.setLayoutData(btnUninstall, new GridData());
Messages.setLanguageText(btnUninstall, "ConfigView.pluginlist.uninstallSelected");
btnUninstall.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
btnUninstall.setEnabled(false);
final int[] items = table.getSelectionIndices();
new AEThread2("uninstall") {
@Override
public void run() {
try {
List<PluginInterface> pis = new ArrayList<>();
for (int i = 0; i < items.length; i++) {
int index = items[i];
if (index >= 0 && index < pluginIFs.size()) {
PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
pis.add(pluginIF);
}
}
if (pis.size() > 0) {
PluginInterface[] ps = new PluginInterface[pis.size()];
pis.toArray(ps);
try {
final AESemaphore wait_sem = new AESemaphore("unist:wait");
ps[0].getPluginManager().getPluginInstaller().uninstall(ps, new PluginInstallationListener() {
@Override
public void completed() {
wait_sem.release();
}
@Override
public void cancelled() {
wait_sem.release();
}
@Override
public void failed(PluginException e) {
wait_sem.release();
}
});
wait_sem.reserve();
} catch (Exception e) {
Debug.printStackTrace(e);
}
}
} finally {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
pluginIFs = rebuildPluginIFs();
table.setItemCount(pluginIFs.size());
Collections.sort(pluginIFs, comparator);
table.clearAll();
table.setSelection(new int[0]);
}
});
}
}
}.start();
}
});
btnUninstall.setEnabled(false);
table.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = table.indexOf(item);
PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
for (int i = 0; i < COLUMN_HEADERS.length; i++) {
if (i == FilterComparator.FIELD_NAME)
item.setImage(i, pluginIF.getPluginState().isOperational() ? imgGreenLed : imgRedLed);
String sText = comparator.getFieldValue(i, pluginIF);
if (sText == null)
sText = "";
item.setText(i, sText);
}
item.setGrayed(pluginIF.getPluginState().isMandatory());
boolean bEnabled = pluginIF.getPluginState().isLoadedAtStartup();
Utils.setCheckedInSetData(item, bEnabled);
item.setData("PluginID", pluginIF.getPluginID());
Utils.alternateRowBackground(item);
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
TableItem[] items = table.getSelection();
if (items.length == 1) {
int index = table.indexOf(items[0]);
PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
PluginConfigModel[] models = pluginIF.getUIManager().getPluginConfigModels();
for (PluginConfigModel model : models) {
if (model.getPluginInterface() == pluginIF) {
if (model instanceof BasicPluginConfigModel) {
String id = ((BasicPluginConfigModel) model).getSection();
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, id);
}
}
}
}
}
}
});
table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem item = (TableItem) e.item;
int index = table.indexOf(item);
PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
if (e.detail == SWT.CHECK) {
if (item.getGrayed()) {
if (!item.getChecked())
item.setChecked(true);
return;
}
pluginIF.getPluginState().setDisabled(!item.getChecked());
pluginIF.getPluginState().setLoadedAtStartup(item.getChecked());
}
btnUnload.setEnabled(pluginIF.getPluginState().isOperational() && pluginIF.getPluginState().isUnloadable());
btnLoad.setEnabled(!pluginIF.getPluginState().isOperational() && !pluginIF.getPluginState().hasFailed());
btnUninstall.setEnabled(!(pluginIF.getPluginState().isBuiltIn() || pluginIF.getPluginState().isMandatory()));
}
});
table.setItemCount(pluginIFs.size());
return infoGroup;
}
Aggregations