use of org.eclipse.swt.browser.ProgressListener in project BiglyBT by BiglySoftware.
the class MessageBoxShell method _open.
private void _open() {
if (instanceID != null) {
if (mapInstances.containsKey(instanceID)) {
MessageBoxShell mb = mapInstances.get(instanceID);
if (mb.shell != null && !mb.shell.isDisposed()) {
mb.shell.open();
return;
}
}
mapInstances.put(instanceID, this);
}
result = -1;
boolean ourParent = false;
if (parent == null || parent.isDisposed()) {
parent = Utils.findAnyShell();
ourParent = true;
if (parent == null || parent.isDisposed()) {
triggerResultListener(result);
return;
}
}
final Display display = parent.getDisplay();
// APPLICATION_MODAL causes some crazy sht to happen on Windows.
// Example: 5 windows open in APPLICATION MODAL mode,
// and somehow none of them show until you do a "Window->Bring To Front"
// which only makes ONE visible
int shell_style = SWT.DIALOG_TRIM | SWT.RESIZE;
if (modal) {
shell_style |= SWT.APPLICATION_MODAL;
}
shell = ShellFactory.createShell(parent, shell_style);
if (title != null) {
shell.setText(title);
}
shell.addListener(SWT.Dispose, new Listener() {
@Override
public void handleEvent(Event event) {
mapInstances.remove(instanceID);
if (iconImageID != null) {
ImageLoader.getInstance().releaseImage(iconImageID);
}
triggerResultListener(result);
if (display != null && !display.isDisposed() && filterListener != null) {
display.removeFilter(SWT.Traverse, filterListener);
}
numOpen--;
}
});
GridLayout gridLayout = new GridLayout();
if (squish) {
gridLayout.verticalSpacing = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.marginLeft = 0;
gridLayout.marginRight = 0;
gridLayout.marginTop = 0;
gridLayout.marginBottom = 0;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
}
shell.setLayout(gridLayout);
Utils.setShellIcon(shell);
UISkinnableSWTListener[] listeners = UISkinnableManagerSWT.getInstance().getSkinnableListeners(MessageBoxShell.class.toString());
for (int i = 0; i < listeners.length; i++) {
listeners[i].skinBeforeComponents(shell, this, relatedObjects);
}
FormData formData;
GridData gridData;
Composite textComposite = shell;
if (imgLeft != null) {
textComposite = new Composite(shell, SWT.NONE);
textComposite.setForeground(shell.getForeground());
GridLayout gl = new GridLayout(2, false);
gl.horizontalSpacing = 10;
textComposite.setLayout(gl);
textComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
Label lblImage = new Label(textComposite, SWT.NONE);
lblImage.setImage(imgLeft);
lblImage.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
} else if (!squish) {
textComposite = new Composite(shell, SWT.NONE);
GridLayout gl = new GridLayout(2, false);
gl.marginWidth = 5;
textComposite.setLayout(gl);
textComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
}
Control linkControl;
if (text != null && text.length() > 0) {
if (useTextBox()) {
linkControl = createTextBox(textComposite, text);
} else {
linkControl = createLinkLabel(textComposite, text);
}
} else {
linkControl = null;
}
if ((html != null && html.length() > 0) || (url != null && url.length() > 0)) {
try {
final BrowserWrapper browser = Utils.createSafeBrowser(shell, SWT.NONE);
if (url != null && url.length() > 0) {
browser.setUrl(url);
} else {
browser.setText(html);
}
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 200;
browser.getControl().setLayoutData(gd);
browser.addProgressListener(new ProgressListener() {
@Override
public void completed(ProgressEvent event) {
if (shell == null || shell.isDisposed()) {
return;
}
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
event.doit = browser_follow_links;
}
@Override
public void changed(LocationEvent event) {
}
});
browser.addOpenWindowListener(new BrowserWrapper.OpenWindowListener() {
@Override
public void open(BrowserWrapper.WindowEvent event) {
event.setRequired(true);
}
});
}
@Override
public void changed(ProgressEvent event) {
}
});
browser.addStatusTextListener(new StatusTextListener() {
@Override
public void changed(StatusTextEvent event) {
if (STATUS_TEXT_CLOSE.equals(event.text)) {
// For some reason disposing the shell / browser in the same Thread makes
// ieframe.dll crash on windows.
Utils.execSWTThreadLater(0, new Runnable() {
@Override
public void run() {
if (!browser.isDisposed() && !shell.isDisposed()) {
shell.close();
}
}
});
}
}
});
} catch (Exception e) {
Debug.out(e);
if (html != null) {
Text text = new Text(shell, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP);
text.setText(html);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 200;
text.setLayoutData(gd);
}
}
if (linkControl != null) {
gridData = new GridData(GridData.FILL_HORIZONTAL);
linkControl.setLayoutData(gridData);
}
} else {
if (linkControl != null) {
gridData = new GridData(GridData.FILL_BOTH);
linkControl.setLayoutData(gridData);
}
}
if (!squish && (autoCloseInMS > 0 || rememberID != null || (cbMessageID != null && Utils.getUserMode() >= cbMinUserMode))) {
Label lblPadding = new Label(shell, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.heightHint = 5;
lblPadding.setLayoutData(gridData);
}
// Closing in..
if (autoCloseInMS > 0) {
final BufferedLabel lblCloseIn = new BufferedLabel(shell, SWT.WRAP | SWT.DOUBLE_BUFFERED);
lblCloseIn.setForeground(shell.getForeground());
gridData = new GridData(GridData.FILL_HORIZONTAL);
if (!squish) {
gridData.horizontalIndent = 5;
}
lblCloseIn.setText(MessageText.getString("popup.closing.in", new String[] { String.valueOf(autoCloseInMS / 1000) }));
lblCloseIn.setLayoutData(gridData);
long endOn = SystemTime.getCurrentTime() + autoCloseInMS;
lblCloseIn.setData("CloseOn", new Long(endOn));
SimpleTimer.addPeriodicEvent("autoclose", 500, new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
if (shell.isDisposed()) {
event.cancel();
return;
}
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (!shell.isDisposed()) {
boolean bDelayPaused = lblCloseIn.getData("DelayPaused") != null;
if (bDelayPaused) {
return;
}
long endOn = ((Long) lblCloseIn.getData("CloseOn")).longValue();
if (SystemTime.getCurrentTime() > endOn) {
result = defaultButtonPos;
autoClosed = true;
shell.dispose();
} else {
String sText = "";
if (lblCloseIn.isDisposed())
return;
if (!bDelayPaused) {
long delaySecs = (endOn - SystemTime.getCurrentTime()) / 1000;
sText = MessageText.getString("popup.closing.in", new String[] { String.valueOf(delaySecs) });
}
lblCloseIn.setText(sText);
}
}
}
});
}
});
SimpleTimer.addPeriodicEvent("OverPopup", 100, new TimerEventPerformer() {
boolean wasOver = true;
long lEnterOn = 0;
@Override
public void perform(final TimerEvent event) {
if (shell.isDisposed()) {
event.cancel();
return;
}
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (shell.isDisposed()) {
event.cancel();
return;
}
boolean isOver = shell.getBounds().contains(shell.getDisplay().getCursorLocation());
if (isOver != wasOver) {
wasOver = isOver;
if (isOver) {
lblCloseIn.setData("DelayPaused", "");
lEnterOn = SystemTime.getCurrentTime();
lblCloseIn.setText("");
} else {
lblCloseIn.setData("DelayPaused", null);
if (lEnterOn > 0) {
long diff = SystemTime.getCurrentTime() - lEnterOn;
long endOn = ((Long) lblCloseIn.getData("CloseOn")).longValue() + diff;
lblCloseIn.setData("CloseOn", new Long(endOn));
}
}
}
}
});
}
});
}
boolean needSpacer = true;
if (cbMessageID != null && Utils.getUserMode() >= cbMinUserMode) {
needSpacer = false;
Button cb = new Button(shell, SWT.CHECK);
cb.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
cbEnabled = ((Button) e.widget).getSelection();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
Messages.setLanguageText(cb, cbMessageID);
cb.setSelection(cbEnabled);
}
if (rememberID != null) {
Button checkRemember = new Button(shell, SWT.CHECK);
checkRemember.setText(rememberText);
checkRemember.setSelection(rememberByDefault);
isRemembered = rememberByDefault;
checkRemember.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
Button checkRemember = (Button) event.widget;
isRemembered = checkRemember.getSelection();
}
});
checkRemember.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
Button checkRemember = (Button) e.widget;
isRemembered = checkRemember != null && checkRemember.getSelection();
if (rememberID != null && isRemembered && (rememberOnlyIfButtonPos == -1 || rememberOnlyIfButtonPos == result)) {
RememberedDecisionsManager.setRemembered(rememberID, getButtonVal(result));
}
}
});
} else if (supportsApplyToAll) {
Button appkyToAll = new Button(shell, SWT.CHECK);
appkyToAll.setText(MessageText.getString("label.apply.to.all"));
appkyToAll.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
Button button = (Button) event.widget;
applyToAll = button.getSelection();
}
});
} else if (needSpacer) {
Button spacer = new Button(shell, SWT.CHECK);
spacer.setVisible(false);
}
if (buttons.length > 0) {
Canvas line = new Canvas(shell, SWT.NO_BACKGROUND);
line.addListener(SWT.Paint, new Listener() {
@Override
public void handleEvent(Event e) {
Rectangle clientArea = ((Canvas) e.widget).getClientArea();
e.gc.setForeground(Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_NORMAL_SHADOW));
e.gc.drawRectangle(clientArea);
clientArea.y++;
e.gc.setForeground(Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
e.gc.drawRectangle(clientArea);
}
});
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.heightHint = 2;
line.setLayoutData(gridData);
Composite cButtons = new Composite(shell, SWT.NONE);
FormLayout layout = new FormLayout();
cButtons.setLayout(layout);
gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
cButtons.setLayoutData(gridData);
Control lastButton = null;
Listener buttonListener = new Listener() {
@Override
public void handleEvent(Event event) {
result = ((Integer) event.widget.getData()).intValue();
shell.dispose();
}
};
int buttonWidth = 0;
Button[] swtButtons = new Button[buttons.length];
for (int i = 0; i < buttons.length; i++) {
Button button = new Button(cButtons, SWT.PUSH);
swtButtons[i] = button;
button.setData(Integer.valueOf(i));
button.setText(buttons[i]);
button.addListener(SWT.Selection, buttonListener);
formData = new FormData();
if (lastButton != null) {
formData.left = new FormAttachment(lastButton, 5);
}
button.setLayoutData(formData);
Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
if (size.x > buttonWidth) {
buttonWidth = size.x;
}
if (i == defaultButtonPos) {
button.setFocus();
shell.setDefaultButton(button);
}
lastButton = button;
}
if (buttonWidth > 0) {
if (buttonWidth < MIN_BUTTON_SIZE) {
buttonWidth = MIN_BUTTON_SIZE;
}
for (int i = 0; i < buttons.length; i++) {
Point size = swtButtons[i].computeSize(buttonWidth, SWT.DEFAULT);
swtButtons[i].setSize(size);
formData = (FormData) swtButtons[i].getLayoutData();
formData.width = buttonWidth;
}
}
}
shell.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent event) {
if (event.detail == SWT.TRAVERSE_ESCAPE) {
shell.dispose();
}
}
});
filterListener = new Listener() {
@Override
public void handleEvent(Event event) {
if (event.detail == SWT.TRAVERSE_ARROW_NEXT) {
event.detail = SWT.TRAVERSE_TAB_NEXT;
event.doit = true;
} else if (event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
event.detail = SWT.TRAVERSE_TAB_PREVIOUS;
event.doit = true;
}
}
};
display.addFilter(SWT.Traverse, filterListener);
shell.pack();
Point size = shell.getSize();
if (size.x < min_size_x) {
size.x = min_size_x;
shell.setSize(size);
} else if (size.x > max_size_x) {
size = shell.computeSize(max_size_x, SWT.DEFAULT);
shell.setSize(size);
}
if (size.y < min_size_y) {
size.y = min_size_y;
shell.setSize(size);
}
Shell centerRelativeToShell = parent;
if (ourParent) {
Control cursorControl = display.getCursorControl();
if (cursorControl != null) {
centerRelativeToShell = cursorControl.getShell();
}
}
Utils.centerWindowRelativeTo(shell, centerRelativeToShell);
for (int i = 0; i < listeners.length; i++) {
listeners[i].skinAfterComponents(shell, this, relatedObjects);
}
shell.open();
opened = true;
numOpen++;
return;
}
use of org.eclipse.swt.browser.ProgressListener in project BiglyBT by BiglySoftware.
the class ExternalLoginWindow method setCaptureMethod.
protected void setCaptureMethod(final BrowserWrapper browser, boolean transparent, boolean show_progress) {
if (sniffer != null) {
sniffer.destroy();
sniffer = null;
}
if (show_progress) {
final ProgressWindow prog_wind = new ProgressWindow(shell, "externalLogin.wait", SWT.DIALOG_TRIM, 500);
browser.addProgressListener(new ProgressListener() {
@Override
public void changed(ProgressEvent arg0) {
}
@Override
public void completed(ProgressEvent arg0) {
if (browser.isDisposed() || browser.getShell().isDisposed()) {
return;
}
browser.removeProgressListener(this);
prog_wind.destroy();
}
});
}
if (transparent) {
browser.setUrl(originalLoginUrl);
} else {
try {
final HTTPAuthHelper this_sniffer = sniffer = new HTTPAuthHelper(new URL(originalLoginUrl));
this_sniffer.addListener(new HTTPAuthHelperListener() {
@Override
public void cookieFound(HTTPAuthHelper helper, String cookie_name, String cookie_value) {
if (helper == this_sniffer) {
foundCookies(cookie_name + "=" + cookie_value, false);
}
}
});
this_sniffer.start();
String str = originalLoginUrl.toString();
int pos = str.indexOf("://");
str = str.substring(pos + 3);
pos = str.indexOf("/");
if (pos != -1) {
str = str.substring(pos);
}
if (!str.startsWith("/")) {
str = "/" + str;
}
browser.setUrl("http://localhost:" + sniffer.getPort() + str);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
use of org.eclipse.swt.browser.ProgressListener in project knime-workbench by knime.
the class SubnodeLayoutJSONEditorPage method createVisualLayoutComposite.
private Composite createVisualLayoutComposite(final Composite parent) {
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// Web resources
final WebTemplate template = WebTemplateUtil.getWebTemplateFromBundleID("knimeLayoutEditor_1.0.0");
final WebTemplate dT = WebTemplateUtil.getWebTemplateFromBundleID("knimeLayoutEditor_1.0.0_Debug");
VisualLayoutViewCreator creator = new VisualLayoutViewCreator(template, dT);
String html = "";
try {
html = creator.createWebResources("visual layout editor", null, null, "");
} catch (final IOException e) {
LOGGER.error("Cannot create visual layout editor", e);
}
// Create browser
m_browser = new Browser(composite, SWT.NONE);
try {
m_browser.setUrl(new File(html).toURI().toURL().toString());
} catch (MalformedURLException e) {
LOGGER.error(e.getMessage(), e);
}
m_browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// Create JSON Objects
final List<VisualLayoutEditorJSONNode> nodes = createJSONNodeList();
// ensure node layout is written the same as the metanode layout
final ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
String jsonNodes = "";
try {
jsonNodes = mapper.writeValueAsString(nodes);
} catch (JsonProcessingException e) {
LOGGER.error("Cannot write JSON: " + e.getMessage(), e);
}
// variables in progress listener must be final
final String jsonLayoutConst = getJsonDocument();
final String jsonNodesConst = jsonNodes;
m_browser.addProgressListener(new ProgressListener() {
@Override
public void changed(final ProgressEvent event) {
// do nothing
}
@Override
public void completed(final ProgressEvent event) {
m_browser.evaluate("setNodes(\'" + jsonNodesConst + "\');");
m_browser.evaluate("setLayout(\'" + jsonLayoutConst + "\');");
}
});
m_visualLayoutUpdate = new UpdateLayoutFunction(m_browser, "pushLayout");
return composite;
}
use of org.eclipse.swt.browser.ProgressListener in project eclipse.platform.swt by eclipse-platform.
the class Test_org_eclipse_swt_browser_Browser method test_ProgressListener_newListener_closeShell.
@Test
public void test_ProgressListener_newListener_closeShell() {
Display display = Display.getCurrent();
Shell shell = new Shell(display);
Browser browser = new Browser(shell, SWT.NONE);
browser.addProgressListener(new ProgressListener() {
@Override
public void changed(ProgressEvent event) {
}
@Override
public void completed(ProgressEvent event) {
}
});
shell.close();
}
use of org.eclipse.swt.browser.ProgressListener in project eclipse.platform.swt by eclipse-platform.
the class Test_org_eclipse_swt_browser_Browser method test_ProgressListener_completed_Called.
@Test
public void test_ProgressListener_completed_Called() {
AtomicBoolean childCompleted = new AtomicBoolean(false);
ProgressListener l = new ProgressListener() {
@Override
public void completed(ProgressEvent event) {
childCompleted.set(true);
}
@Override
public void changed(ProgressEvent event) {
}
};
browser.addProgressListener(l);
browser.setText("<html><body>This test ensures that the completed listener is called.</body></html>");
shell.open();
boolean passed = waitForPassCondition(childCompleted::get);
assertTrue(passed);
}
Aggregations