Search in sources :

Example 11 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor in project netxms by netxms.

the class ApplicationWorkbenchWindowAdvisor method postWindowCreate.

/* (non-Javadoc)
	 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowCreate()
	 */
@Override
public void postWindowCreate() {
    super.postWindowCreate();
    NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    // Changes the page title at runtime
    JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
    if (executor != null) {
        StringBuilder js = new StringBuilder();
        // $NON-NLS-1$
        js.append("document.title = ");
        js.append("\"");
        js.append(BrandingManager.getInstance().getProductName());
        js.append(" - [");
        js.append(session.getUserName());
        js.append("@");
        js.append(session.getServerAddress());
        js.append("]");
        js.append("\"");
        executor.execute(js.toString());
    }
    BindingService service = (BindingService) getWindowConfigurer().getWindow().getWorkbench().getService(IBindingService.class);
    BindingManager bindingManager = service.getBindingManager();
    try {
        // $NON-NLS-1$
        bindingManager.setActiveScheme(service.getScheme("org.netxms.ui.eclipse.defaultKeyBinding"));
    } catch (NotDefinedException e) {
        e.printStackTrace();
    }
    final Shell shell = getWindowConfigurer().getWindow().getShell();
    shell.setMaximized(true);
    for (Control ctrl : shell.getChildren()) {
        // $NON-NLS-1$
        ctrl.setData(RWT.CUSTOM_VARIANT, "gray");
        if (ctrl instanceof CBanner) {
            for (Control cc : ((CBanner) ctrl).getChildren()) // $NON-NLS-1$
            cc.setData(RWT.CUSTOM_VARIANT, "gray");
        } else if (// $NON-NLS-1$
        ctrl.getClass().getName().equals("org.eclipse.swt.widgets.Composite")) {
            for (Control cc : ((Composite) ctrl).getChildren()) // $NON-NLS-1$
            cc.setData(RWT.CUSTOM_VARIANT, "gray");
        }
    }
    Menu menuBar = shell.getMenuBar();
    if (menuBar != null)
        // $NON-NLS-1$
        menuBar.setData(RWT.CUSTOM_VARIANT, "menuBar");
}
Also used : BindingManager(org.eclipse.jface.bindings.BindingManager) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) NXCSession(org.netxms.client.NXCSession) BindingService(org.eclipse.ui.internal.keys.BindingService) IBindingService(org.eclipse.ui.keys.IBindingService) CBanner(org.eclipse.swt.custom.CBanner) JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) Menu(org.eclipse.swt.widgets.Menu) IBindingService(org.eclipse.ui.keys.IBindingService)

Example 12 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor in project netxms by netxms.

the class WidgetHelper method copyToClipboard.

/**
 * Copy given text to clipboard
 *
 * @param text
 */
public static void copyToClipboard(final String text) {
    JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
    if (executor != null) {
        StringBuilder js = new StringBuilder();
        // $NON-NLS-1$
        js.append("copyTextToClipboard(\'" + text + "\');");
        executor.execute(js.toString());
    }
}
Also used : JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor)

Example 13 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor in project netxms by netxms.

the class AlarmNotifier method processNewAlarm.

/**
 * Process new alarm
 */
private void processNewAlarm(final Alarm alarm) {
    if (alarm.getState() != Alarm.STATE_OUTSTANDING)
        return;
    String fileName;
    try {
        fileName = getSoundAndDownloadIfRequired(SEVERITY_TEXT[alarm.getCurrentSeverity().getValue()]);
    } catch (ArrayIndexOutOfBoundsException e) {
        // $NON-NLS-1$
        Activator.logError("Invalid alarm severity", e);
        fileName = null;
    }
    if ((fileName != null) && !fileName.isEmpty()) {
        JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
        File localFile = new File(workspaceUrl.getPath(), fileName);
        String id = "audio-" + fileName;
        // $NON-NLS-1$
        DownloadServiceHandler.addDownload(id, fileName, localFile, "audio/wav");
        StringBuilder js = new StringBuilder();
        js.append("var testAudio = document.createElement('audio');");
        js.append("if (testAudio.canPlayType !== undefined)");
        js.append("{");
        // $NON-NLS-1$
        js.append("var audio = new Audio('");
        js.append(DownloadServiceHandler.createDownloadUrl(id));
        // $NON-NLS-1$
        js.append("');");
        // $NON-NLS-1$
        js.append("audio.play();");
        js.append("}");
        executor.execute(js.toString());
    }
}
Also used : JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor) File(java.io.File)

Example 14 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor in project rap by entirej.

the class EJRWTApplicationLauncher method reloadApplication.

public static void reloadApplication(EJFrameworkHelper frameworkHelper) {
    // disable due to RWT bug
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=410895
    // ExitConfirmation confirmation =
    // RWT.getClient().getService(ExitConfirmation.class);
    // confirmation.setMessage(null);
    StringBuffer url = new StringBuffer();
    url.append(RWT.getRequest().getContextPath());
    url.append(RWT.getRequest().getServletPath());
    String encodeURL = RWT.getResponse().encodeURL(url.toString());
    if (encodeURL.contains("jsessionid")) {
        encodeURL = encodeURL.substring(0, encodeURL.indexOf("jsessionid"));
    }
    String browserText = MessageFormat.format("parent.window.location.href = \"{0}\";", encodeURL);
    JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
    if (executor != null) {
        executor.execute(browserText);
    }
}
Also used : JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor)

Example 15 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor in project rap by entirej.

the class EJRWTFileDownload method download.

public static void download(String sourcePath, String outputName) {
    File file = new File(sourcePath);
    if (!file.exists()) {
        throw new EJApplicationException(String.format("File not found :%s", file.getName()));
    }
    UUID randomUUID = UUID.randomUUID();
    String fileKey = randomUUID.toString();
    keys.put(fileKey, sourcePath);
    StringBuffer url = new StringBuffer();
    url.append(RWT.getServiceManager().getServiceHandlerUrl(SERVICE_HANDLER));
    url.append("&filename=");
    url.append(fileKey);
    url.append("&output=");
    url.append(outputName);
    String encodedURL = RWT.getResponse().encodeURL(url.toString());
    // UrlLauncher urlLauncher =
    // RWT.getClient().getService(UrlLauncher.class);
    // urlLauncher.openURL(encodedURL);
    JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class);
    javaScriptExecutor.execute(String.format("window.location = '%s'", encodedURL));
}
Also used : JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor) EJApplicationException(org.entirej.framework.core.EJApplicationException) UUID(java.util.UUID) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

JavaScriptExecutor (org.eclipse.rap.rwt.client.service.JavaScriptExecutor)17 File (java.io.File)3 IOException (java.io.IOException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NXCSession (org.netxms.client.NXCSession)2 RandomAccessFile (java.io.RandomAccessFile)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Properties (java.util.Properties)1 UUID (java.util.UUID)1 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)1 IStatus (org.eclipse.core.runtime.IStatus)1 BindingManager (org.eclipse.jface.bindings.BindingManager)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Window (org.eclipse.jface.window.Window)1 CBanner (org.eclipse.swt.custom.CBanner)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 GridData (org.eclipse.swt.layout.GridData)1