use of com.biglybt.ui.swt.TextViewerWindow in project BiglyBT by BiglySoftware.
the class ConfigSectionConnectionProxy method configSectionCreate.
@Override
public Composite configSectionCreate(final Composite parent) {
GridData gridData;
GridLayout layout;
Composite cSection = new Composite(parent, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
Utils.setLayoutData(cSection, gridData);
layout = new GridLayout();
layout.numColumns = 2;
cSection.setLayout(layout);
int userMode = COConfigurationManager.getIntParameter("User Mode");
if (userMode < REQUIRED_MODE) {
Label label = new Label(cSection, SWT.WRAP);
gridData = new GridData();
gridData.horizontalSpan = 2;
Utils.setLayoutData(label, gridData);
final String[] modeKeys = { "ConfigView.section.mode.beginner", "ConfigView.section.mode.intermediate", "ConfigView.section.mode.advanced" };
String param1, param2;
if (REQUIRED_MODE < modeKeys.length)
param1 = MessageText.getString(modeKeys[REQUIRED_MODE]);
else
param1 = String.valueOf(REQUIRED_MODE);
if (userMode < modeKeys.length)
param2 = MessageText.getString(modeKeys[userMode]);
else
param2 = String.valueOf(userMode);
label.setText(MessageText.getString("ConfigView.notAvailableForMode", new String[] { param1, param2 }));
return cSection;
}
// //////////////////// PROXY GROUP /////////////////
Group gProxyTracker = new Group(cSection, SWT.NULL);
Messages.setLanguageText(gProxyTracker, "ConfigView.section.proxy.group.tracker");
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
Utils.setLayoutData(gProxyTracker, gridData);
layout = new GridLayout();
layout.numColumns = 2;
gProxyTracker.setLayout(layout);
final BooleanParameter enableProxy = new BooleanParameter(gProxyTracker, "Enable.Proxy", "ConfigView.section.proxy.enable_proxy");
gridData = new GridData();
gridData.horizontalSpan = 2;
enableProxy.setLayoutData(gridData);
final BooleanParameter enableSocks = new BooleanParameter(gProxyTracker, "Enable.SOCKS", "ConfigView.section.proxy.enable_socks");
gridData = new GridData();
gridData.horizontalSpan = 2;
enableSocks.setLayoutData(gridData);
Label lHost = new Label(gProxyTracker, SWT.NULL);
Messages.setLanguageText(lHost, "ConfigView.section.proxy.host");
final StringParameter pHost = new StringParameter(gProxyTracker, "Proxy.Host", "", false);
gridData = new GridData();
gridData.widthHint = 105;
pHost.setLayoutData(gridData);
Label lPort = new Label(gProxyTracker, SWT.NULL);
Messages.setLanguageText(lPort, "ConfigView.section.proxy.port");
final StringParameter pPort = new StringParameter(gProxyTracker, "Proxy.Port", "", false);
gridData = new GridData();
gridData.widthHint = 40;
pPort.setLayoutData(gridData);
Label lUser = new Label(gProxyTracker, SWT.NULL);
Messages.setLanguageText(lUser, "ConfigView.section.proxy.username");
final StringParameter pUser = new StringParameter(gProxyTracker, "Proxy.Username", false);
gridData = new GridData();
gridData.widthHint = 105;
pUser.setLayoutData(gridData);
Label lPass = new Label(gProxyTracker, SWT.NULL);
Messages.setLanguageText(lPass, "ConfigView.section.proxy.password");
final StringParameter pPass = new StringParameter(gProxyTracker, "Proxy.Password", "", false);
gridData = new GridData();
gridData.widthHint = 105;
pPass.setLayoutData(gridData);
final BooleanParameter trackerDNSKill = new BooleanParameter(gProxyTracker, "Proxy.SOCKS.Tracker.DNS.Disable", "ConfigView.section.proxy.no.local.dns");
gridData = new GridData();
gridData.horizontalSpan = 2;
trackerDNSKill.setLayoutData(gridData);
final NetworkAdminSocksProxy[] test_proxy = { null };
final Button test_socks = new Button(gProxyTracker, SWT.PUSH);
Messages.setLanguageText(test_socks, "ConfigView.section.proxy.testsocks");
test_socks.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
final NetworkAdminSocksProxy target;
synchronized (test_proxy) {
target = test_proxy[0];
}
if (target != null) {
final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("ConfigView.section.proxy.testsocks.title"), null, "Testing SOCKS connection to " + target.getHost() + ":" + target.getPort(), false);
final AESemaphore test_done = new AESemaphore("");
new AEThread2("SOCKS test") {
@Override
public void run() {
try {
String[] vers = target.getVersionsSupported();
String ver = "";
for (String v : vers) {
ver += (ver.length() == 0 ? "" : ", ") + v;
}
appendText(viewer, "\r\nConnection OK - supported version(s): " + ver);
} catch (Throwable e) {
appendText(viewer, "\r\n" + Debug.getNestedExceptionMessage(e));
} finally {
test_done.release();
}
}
}.start();
new AEThread2("SOCKS test dotter") {
@Override
public void run() {
while (!test_done.reserveIfAvailable()) {
appendText(viewer, ".");
try {
Thread.sleep(500);
} catch (Throwable e) {
break;
}
}
}
}.start();
}
}
private void appendText(final TextViewerWindow viewer, final String line) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (!viewer.isDisposed()) {
viewer.append2(line);
}
}
});
}
});
Parameter[] socks_params = { enableProxy, enableSocks, pHost, pPort, pUser, pPass, trackerDNSKill };
ParameterChangeAdapter socks_adapter = new ParameterChangeAdapter() {
@Override
public void parameterChanged(Parameter p, boolean caused_internally) {
if (test_socks.isDisposed()) {
p.removeChangeListener(this);
} else {
if (!caused_internally) {
boolean enabled = enableProxy.isSelected() && enableSocks.isSelected() && pHost.getValue().trim().length() > 0 && pPort.getValue().trim().length() > 0;
boolean socks_enabled = enableProxy.isSelected() && enableSocks.isSelected();
trackerDNSKill.setEnabled(socks_enabled);
if (enabled) {
try {
int port = Integer.parseInt(pPort.getValue());
NetworkAdminSocksProxy nasp = NetworkAdmin.getSingleton().createSocksProxy(pHost.getValue(), port, pUser.getValue(), pPass.getValue());
synchronized (test_proxy) {
test_proxy[0] = nasp;
}
} catch (Throwable e) {
enabled = false;
}
}
if (!enabled) {
synchronized (test_proxy) {
test_proxy[0] = null;
}
}
final boolean f_enabled = enabled;
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (!test_socks.isDisposed()) {
test_socks.setEnabled(f_enabled);
}
}
});
}
}
}
};
for (Parameter p : socks_params) {
p.addChangeListener(socks_adapter);
}
// init settings
socks_adapter.parameterChanged(null, false);
// //////////////////////////////////////////////
Group gProxyPeer = new Group(cSection, SWT.NULL);
Messages.setLanguageText(gProxyPeer, "ConfigView.section.proxy.group.peer");
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
Utils.setLayoutData(gProxyPeer, gridData);
layout = new GridLayout();
layout.numColumns = 2;
gProxyPeer.setLayout(layout);
final BooleanParameter enableSocksPeer = new BooleanParameter(gProxyPeer, "Proxy.Data.Enable", "ConfigView.section.proxy.enable_socks.peer");
gridData = new GridData();
gridData.horizontalSpan = 2;
enableSocksPeer.setLayoutData(gridData);
final BooleanParameter socksPeerInform = new BooleanParameter(gProxyPeer, "Proxy.Data.SOCKS.inform", "ConfigView.section.proxy.peer.informtracker");
gridData = new GridData();
gridData.horizontalSpan = 2;
socksPeerInform.setLayoutData(gridData);
Label lSocksVersion = new Label(gProxyPeer, SWT.NULL);
Messages.setLanguageText(lSocksVersion, "ConfigView.section.proxy.socks.version");
String[] socks_types = { "V4", "V4a", "V5" };
String[] dropLabels = new String[socks_types.length];
String[] dropValues = new String[socks_types.length];
for (int i = 0; i < socks_types.length; i++) {
dropLabels[i] = socks_types[i];
dropValues[i] = socks_types[i];
}
final StringListParameter socksType = new StringListParameter(gProxyPeer, "Proxy.Data.SOCKS.version", "V4", dropLabels, dropValues);
final BooleanParameter sameConfig = new BooleanParameter(gProxyPeer, "Proxy.Data.Same", "ConfigView.section.proxy.peer.same");
gridData = new GridData();
gridData.horizontalSpan = 2;
sameConfig.setLayoutData(gridData);
Label lDataHost = new Label(gProxyPeer, SWT.NULL);
Messages.setLanguageText(lDataHost, "ConfigView.section.proxy.host");
StringParameter pDataHost = new StringParameter(gProxyPeer, "Proxy.Data.Host", "");
gridData = new GridData();
gridData.widthHint = 105;
pDataHost.setLayoutData(gridData);
Label lDataPort = new Label(gProxyPeer, SWT.NULL);
Messages.setLanguageText(lDataPort, "ConfigView.section.proxy.port");
StringParameter pDataPort = new StringParameter(gProxyPeer, "Proxy.Data.Port", "");
gridData = new GridData();
gridData.widthHint = 40;
pDataPort.setLayoutData(gridData);
Label lDataUser = new Label(gProxyPeer, SWT.NULL);
Messages.setLanguageText(lDataUser, "ConfigView.section.proxy.username");
StringParameter pDataUser = new StringParameter(gProxyPeer, "Proxy.Data.Username");
gridData = new GridData();
gridData.widthHint = 105;
pDataUser.setLayoutData(gridData);
Label lDataPass = new Label(gProxyPeer, SWT.NULL);
Messages.setLanguageText(lDataPass, "ConfigView.section.proxy.password");
StringParameter pDataPass = new StringParameter(gProxyPeer, "Proxy.Data.Password", "");
gridData = new GridData();
gridData.widthHint = 105;
pDataPass.setLayoutData(gridData);
final Control[] proxy_controls = new Control[] { enableSocks.getControl(), lHost, pHost.getControl(), lPort, pPort.getControl(), lUser, pUser.getControl(), lPass, pPass.getControl() };
IAdditionalActionPerformer proxy_enabler = new GenericActionPerformer(new Control[] {}) {
@Override
public void performAction() {
for (int i = 0; i < proxy_controls.length; i++) {
proxy_controls[i].setEnabled(enableProxy.isSelected());
}
}
};
final Control[] proxy_peer_controls = new Control[] { lDataHost, pDataHost.getControl(), lDataPort, pDataPort.getControl(), lDataUser, pDataUser.getControl(), lDataPass, pDataPass.getControl() };
final Control[] proxy_peer_details = new Control[] { sameConfig.getControl(), socksPeerInform.getControl(), socksType.getControl(), lSocksVersion };
IAdditionalActionPerformer proxy_peer_enabler = new GenericActionPerformer(new Control[] {}) {
@Override
public void performAction() {
for (int i = 0; i < proxy_peer_controls.length; i++) {
proxy_peer_controls[i].setEnabled(enableSocksPeer.isSelected() && !sameConfig.isSelected());
}
for (int i = 0; i < proxy_peer_details.length; i++) {
proxy_peer_details[i].setEnabled(enableSocksPeer.isSelected());
}
}
};
enableSocks.setAdditionalActionPerformer(proxy_enabler);
enableProxy.setAdditionalActionPerformer(proxy_enabler);
enableSocksPeer.setAdditionalActionPerformer(proxy_peer_enabler);
sameConfig.setAdditionalActionPerformer(proxy_peer_enabler);
// dns info
Label label = new Label(cSection, SWT.WRAP);
Messages.setLanguageText(label, "ConfigView.section.proxy.dns.info");
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
// needed for wrap
gridData.widthHint = 200;
Utils.setLayoutData(label, gridData);
// disable plugin proxies
final BooleanParameter disablepps = new BooleanParameter(cSection, "Proxy.SOCKS.disable.plugin.proxies", "ConfigView.section.proxy.disable.plugin.proxies");
gridData = new GridData();
gridData.horizontalSpan = 2;
disablepps.setLayoutData(gridData);
// check on start
final BooleanParameter checkOnStart = new BooleanParameter(cSection, "Proxy.Check.On.Start", "ConfigView.section.proxy.check.on.start");
gridData = new GridData();
gridData.horizontalSpan = 2;
checkOnStart.setLayoutData(gridData);
// icon
final BooleanParameter showIcon = new BooleanParameter(cSection, "Proxy.SOCKS.ShowIcon", "ConfigView.section.proxy.show_icon");
gridData = new GridData();
gridData.horizontalSpan = 2;
showIcon.setLayoutData(gridData);
final BooleanParameter flagIncoming = new BooleanParameter(cSection, "Proxy.SOCKS.ShowIcon.FlagIncoming", "ConfigView.section.proxy.show_icon.flag.incoming");
gridData = new GridData();
gridData.horizontalIndent = 50;
gridData.horizontalSpan = 2;
flagIncoming.setLayoutData(gridData);
showIcon.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(flagIncoming));
// username info
label = new Label(cSection, SWT.WRAP);
gridData = new GridData();
gridData.horizontalSpan = 2;
Utils.setLayoutData(label, gridData);
label.setText(MessageText.getString("ConfigView.section.proxy.username.info"));
return cSection;
}
use of com.biglybt.ui.swt.TextViewerWindow in project BiglyBT by BiglySoftware.
the class ConfigSectionBackupRestore method runBackup.
private void runBackup(BackupManager backup_manager, String path, final Runnable stats_updater) {
final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("br.backup.progress"), null, "", true, true);
viewer.setEditable(false);
viewer.setOKEnabled(false);
BackupManager.BackupListener listener = new BackupManager.BackupListener() {
@Override
public boolean reportProgress(String str) {
return (append(str, false));
}
@Override
public void reportComplete() {
append("Backup Complete!", true);
}
@Override
public void reportError(Throwable error) {
append("Backup Failed: " + Debug.getNestedExceptionMessage(error), true);
}
private boolean append(final String str, final boolean complete) {
if (viewer.isDisposed()) {
return (false);
}
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (str.endsWith("...")) {
viewer.append(str);
} else {
viewer.append(str + "\r\n");
}
if (complete) {
viewer.setOKEnabled(true);
stats_updater.run();
}
}
});
return (true);
}
};
if (path == null) {
backup_manager.runAutoBackup(listener);
} else {
backup_manager.backup(new File(path), listener);
}
viewer.goModal();
}
use of com.biglybt.ui.swt.TextViewerWindow in project BiglyBT by BiglySoftware.
the class ConfigSectionBackupRestore method configSectionCreate.
@Override
public Composite configSectionCreate(final Composite parent) {
ImageLoader imageLoader = ImageLoader.getInstance();
Image imgOpenFolder = imageLoader.getImage("openFolderButton");
GridData gridData;
GridLayout layout;
final Composite cBR = new Composite(parent, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
cBR.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 1;
cBR.setLayout(layout);
Label info_label = new Label(cBR, SWT.WRAP);
Messages.setLanguageText(info_label, "ConfigView.section.br.overview");
gridData = Utils.getWrappableLabelGridData(1, GridData.HORIZONTAL_ALIGN_FILL);
info_label.setLayoutData(gridData);
// wiki link
final Label linkLabel = new Label(cBR, SWT.NULL);
linkLabel.setText(MessageText.getString("ConfigView.label.please.visit.here"));
linkLabel.setData(Constants.URL_WIKI + "w/Backup_And_Restore");
linkLabel.setCursor(linkLabel.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
linkLabel.setForeground(Colors.blue);
gridData = Utils.getWrappableLabelGridData(1, 0);
linkLabel.setLayoutData(gridData);
linkLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
Utils.launch((String) ((Label) arg0.widget).getData());
}
@Override
public void mouseDown(MouseEvent arg0) {
Utils.launch((String) ((Label) arg0.widget).getData());
}
});
ClipboardCopy.addCopyToClipMenu(linkLabel);
final BackupManager backup_manager = BackupManagerFactory.getManager(CoreFactory.getSingleton());
// backup
Group gBackup = new Group(cBR, SWT.NULL);
Messages.setLanguageText(gBackup, "br.backup");
layout = new GridLayout(2, false);
gBackup.setLayout(layout);
gBackup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// info
Label last_backup_label = new Label(gBackup, SWT.NULL);
Messages.setLanguageText(last_backup_label, "br.backup.last.time");
final Label last_backup_time = new Label(gBackup, SWT.NULL);
Label last_backup_error_label = new Label(gBackup, SWT.NULL);
Messages.setLanguageText(last_backup_error_label, "br.backup.last.error");
final Label last_backup_error = new Label(gBackup, SWT.NULL);
final Runnable stats_updater = new Runnable() {
@Override
public void run() {
long backup_time = backup_manager.getLastBackupTime();
last_backup_time.setText(backup_time == 0 ? "" : String.valueOf(new Date(backup_time)));
last_backup_error.setText(backup_manager.getLastBackupError());
}
};
stats_updater.run();
// manual button
Label backup_manual_label = new Label(gBackup, SWT.NULL);
Messages.setLanguageText(backup_manual_label, "br.backup.manual.info");
Button backup_button = new Button(gBackup, SWT.PUSH);
Messages.setLanguageText(backup_button, "br.backup");
backup_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
if (def_dir != null) {
dialog.setFilterPath(def_dir);
}
dialog.setMessage(MessageText.getString("br.backup.folder.info"));
dialog.setText(MessageText.getString("br.backup.folder.title"));
String path = dialog.open();
if (path != null) {
COConfigurationManager.setParameter("br.backup.folder.default", path);
runBackup(backup_manager, path, stats_updater);
}
}
});
final BooleanParameter auto_backup_enable = new BooleanParameter(gBackup, "br.backup.auto.enable", "br.backup.auto.enable");
gridData = new GridData();
gridData.horizontalSpan = 2;
auto_backup_enable.setLayoutData(gridData);
Composite gDefaultDir = new Composite(gBackup, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 3;
layout.marginHeight = 2;
gDefaultDir.setLayout(layout);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
gDefaultDir.setLayoutData(gridData);
Label lblDefaultDir = new Label(gDefaultDir, SWT.NONE);
Messages.setLanguageText(lblDefaultDir, "ConfigView.section.file.defaultdir.ask");
lblDefaultDir.setLayoutData(new GridData());
gridData = new GridData(GridData.FILL_HORIZONTAL);
final StringParameter pathParameter = new StringParameter(gDefaultDir, "br.backup.auto.dir", "");
pathParameter.setLayoutData(gridData);
if (pathParameter.getValue().length() == 0) {
String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
pathParameter.setValue(def_dir);
}
Button browse = new Button(gDefaultDir, SWT.PUSH);
browse.setImage(imgOpenFolder);
imgOpenFolder.setBackground(browse.getBackground());
browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
browse.addListener(SWT.Selection, new Listener() {
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
@Override
public void handleEvent(Event event) {
DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
dialog.setFilterPath(pathParameter.getValue());
dialog.setMessage(MessageText.getString("br.backup.auto.dir.select"));
dialog.setText(MessageText.getString("ConfigView.section.file.defaultdir.ask"));
String path = dialog.open();
if (path != null) {
pathParameter.setValue(path);
COConfigurationManager.setParameter("br.backup.folder.default", path);
}
}
});
Composite gPeriod = new Composite(gDefaultDir, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 6;
layout.marginLeft = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginTop = 0;
layout.marginBottom = 0;
gPeriod.setLayout(layout);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
gPeriod.setLayoutData(gridData);
Label lbl_backup_days = new Label(gPeriod, SWT.NULL);
Messages.setLanguageText(lbl_backup_days, "br.backup.auto.everydays");
IntParameter backup_everydays = new IntParameter(gPeriod, "br.backup.auto.everydays", 0, Integer.MAX_VALUE);
gridData = new GridData();
gridData.horizontalSpan = 2;
backup_everydays.setLayoutData(gridData);
Label lbl_backup_hours = new Label(gPeriod, SWT.NULL);
Messages.setLanguageText(lbl_backup_hours, "br.backup.auto.everyhours");
IntParameter backup_everyhours = new IntParameter(gPeriod, "br.backup.auto.everyhours", 1, Integer.MAX_VALUE);
gridData = new GridData();
gridData.horizontalSpan = 2;
backup_everyhours.setLayoutData(gridData);
// for whatever reason if you set enable synchronously it gets reset :(
Utils.execSWTThreadLater(1, new Runnable() {
public void run() {
backup_everyhours.setEnabled(backup_everydays.getValue() == 0);
}
});
backup_everydays.addChangeListener(new ParameterChangeAdapter() {
@Override
public void parameterChanged(Parameter p, boolean caused_internally) {
backup_everyhours.setEnabled(backup_everydays.getValue() == 0);
}
});
Label lbl_backup_retain = new Label(gDefaultDir, SWT.NULL);
Messages.setLanguageText(lbl_backup_retain, "br.backup.auto.retain");
IntParameter backup_retain = new IntParameter(gDefaultDir, "br.backup.auto.retain", 1, Integer.MAX_VALUE);
gridData = new GridData();
gridData.horizontalSpan = 2;
backup_retain.setLayoutData(gridData);
BooleanParameter chkNotify = new BooleanParameter(gDefaultDir, "br.backup.notify", "br.backup.notify");
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
chkNotify.setLayoutData(gridData);
Label backup_auto_label = new Label(gDefaultDir, SWT.NULL);
Messages.setLanguageText(backup_auto_label, "br.backup.auto.now");
Button backup_auto_button = new Button(gDefaultDir, SWT.PUSH);
Messages.setLanguageText(backup_auto_button, "br.test");
backup_auto_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
runBackup(backup_manager, null, stats_updater);
}
});
auto_backup_enable.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(gDefaultDir));
// restore
Group gRestore = new Group(cBR, SWT.NULL);
Messages.setLanguageText(gRestore, "br.restore");
layout = new GridLayout(2, false);
gRestore.setLayout(layout);
gRestore.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label restore_label = new Label(gRestore, SWT.NULL);
Messages.setLanguageText(restore_label, "br.restore.info");
Button restore_button = new Button(gRestore, SWT.PUSH);
Messages.setLanguageText(restore_button, "br.restore");
restore_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
if (def_dir != null) {
dialog.setFilterPath(def_dir);
}
dialog.setMessage(MessageText.getString("br.restore.folder.info"));
dialog.setText(MessageText.getString("br.restore.folder.title"));
final String path = dialog.open();
if (path != null) {
MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("br.restore.warning.title"), MessageText.getString("br.restore.warning.info"));
mb.setDefaultButtonUsingStyle(SWT.CANCEL);
mb.setParent(parent.getShell());
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int returnVal) {
if (returnVal != SWT.OK) {
return;
}
final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("br.backup.progress"), null, "", true, true);
viewer.setEditable(false);
viewer.setOKEnabled(false);
backup_manager.restore(new File(path), new BackupManager.BackupListener() {
@Override
public boolean reportProgress(String str) {
return (append(str, false));
}
@Override
public void reportComplete() {
append("Restore Complete!", true);
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
MessageBoxShell mb = new MessageBoxShell(SWT.ICON_INFORMATION | SWT.OK, MessageText.getString("ConfigView.section.security.restart.title"), MessageText.getString("ConfigView.section.security.restart.msg"));
mb.setParent(parent.getShell());
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int returnVal) {
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
uiFunctions.dispose(true, false);
}
}
});
}
});
}
@Override
public void reportError(Throwable error) {
append("Restore Failed: " + Debug.getNestedExceptionMessage(error), true);
}
private boolean append(final String str, final boolean complete) {
if (viewer.isDisposed()) {
return (false);
}
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (str.endsWith("...")) {
viewer.append(str);
} else {
viewer.append(str + "\r\n");
}
if (complete) {
viewer.setOKEnabled(true);
}
}
});
return (true);
}
});
viewer.goModal();
}
});
}
}
});
return (cBR);
}
use of com.biglybt.ui.swt.TextViewerWindow in project BiglyBT by BiglySoftware.
the class TransferStatsView method showSOCKSInfo.
private void showSOCKSInfo() {
AEProxySelector proxy_selector = AEProxySelectorFactory.getSelector();
String info = proxy_selector.getInfo();
TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("proxy.info.title"), null, info, false);
}
Aggregations