public static void runInUI(@Nullable Shell shell, @NotNull Runnable runnable) { final Display display = shell == null || shell.isDisposed() ? Display.getDefault() : shell.getDisplay(); if (display.getThread() != Thread.currentThread()) { display.syncExec(runnable); } else { runnable.run(); } }
public void runOnUIThread(final int ui_type, final Runnable runnable) { if (ui_type == UIInstance.UIT_SWT) { Utils.execSWTThread(runnable); } else { runnable.run(); } }
/** @param composite */ private void createInstallationDirectoryGroup(Composite parent) { Group instDirGroup = NSISWizardDialogUtil.createGroup( parent, 2, "installation.directory.group.label", null, false); // $NON-NLS-1$ NSISWizardSettings settings = mWizard.getSettings(); ((GridData) NSISWizardDialogUtil.createLabel( instDirGroup, "installation.directory.label", true, null, isScriptWizard()) .getLayoutData()) .horizontalSpan = 1; //$NON-NLS-1$ final Composite instDirComposite = new Composite(instDirGroup, SWT.NONE); instDirComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final StackLayout instDirLayout = new StackLayout(); instDirComposite.setLayout(instDirLayout); final Combo instDirCombo = NSISWizardDialogUtil.createCombo( instDirComposite, 1, NSISWizardUtil.getPathConstantsAndVariables(settings.getTargetPlatform()), settings.getInstallDir(), false, true, null); final Text instDirText = NSISWizardDialogUtil.createText(instDirComposite, settings.getInstallDir(), 1, true, null); instDirLayout.topControl = instDirCombo; Runnable r = new Runnable() { private String mInstDirParent = ""; // $NON-NLS-1$ private void updateInstDir(NSISWizardSettings settings) { Control topControl; if (isMultiUser()) { if (settings.getInstallDir().startsWith(mInstDirParent)) { String instDir = settings.getInstallDir().substring(mInstDirParent.length()); settings.setInstallDir(instDir); instDirText.setText(instDir); } topControl = instDirText; } else { if (!settings.getInstallDir().startsWith(mInstDirParent)) { String instDir = mInstDirParent + settings.getInstallDir(); settings.setInstallDir(instDir); instDirCombo.setText(instDir); } topControl = instDirCombo; } if (instDirLayout.topControl != topControl) { instDirLayout.topControl = topControl; instDirComposite.layout(true); } validateField(INSTDIR_CHECK); } public void run() { final PropertyChangeListener propertyListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (NSISWizardSettings.INSTALLER_TYPE.equals(evt.getPropertyName()) || NSISWizardSettings.MULTIUSER_INSTALLATION.equals( evt.getPropertyName())) { updateInstDir(mWizard.getSettings()); } else if (NSISWizardSettings.INSTALL_DIR.equals(evt.getPropertyName())) { if (!isMultiUser()) { setInstDirParent(mWizard.getSettings()); } } } }; final INSISWizardSettingsListener settingsListener = new INSISWizardSettingsListener() { public void settingsChanged( NSISWizardSettings oldSettings, final NSISWizardSettings newSettings) { if (oldSettings != null) { oldSettings.removePropertyChangeListener(propertyListener); } setInstDirParent(newSettings); if (newSettings != null) { newSettings.addPropertyChangeListener(propertyListener); } updateInstDir(newSettings); } }; mWizard.addSettingsListener(settingsListener); mWizard.getSettings().addPropertyChangeListener(propertyListener); instDirCombo.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { mWizard.getSettings().removePropertyChangeListener(propertyListener); mWizard.removeSettingsListener(settingsListener); } }); setInstDirParent(mWizard.getSettings()); updateInstDir(mWizard.getSettings()); } private void setInstDirParent(NSISWizardSettings settings) { mInstDirParent = ""; // $NON-NLS-1$ if (settings != null) { String instDir = settings.getInstallDir(); if (!Common.isEmpty(instDir)) { int n = instDir.lastIndexOf('\\'); if (n > 0 && n < instDir.length() - 1) { mInstDirParent = instDir.substring(0, n + 1); } } } } }; r.run(); GridData gd = (GridData) instDirCombo.getLayoutData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; instDirCombo.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { String text = ((Combo) e.widget).getText(); mWizard.getSettings().setInstallDir(text); validateField(INSTDIR_CHECK); } }); instDirText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { String text = ((Text) e.widget).getText(); mWizard.getSettings().setInstallDir(text); validateField(INSTDIR_CHECK); } }); final Button changeInstDir = NSISWizardDialogUtil.createCheckBox( instDirGroup, "change.installation.directory.label", //$NON-NLS-1$ settings.isChangeInstallDir(), (settings.getInstallerType() != INSTALLER_TYPE_SILENT), null, false); changeInstDir.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { mWizard.getSettings().setChangeInstallDir(((Button) e.widget).getSelection()); } }); addPageChangedRunnable( new Runnable() { public void run() { if (isCurrentPage()) { NSISWizardSettings settings = mWizard.getSettings(); instDirCombo.setText(settings.getInstallDir()); changeInstDir.setEnabled(settings.getInstallerType() != INSTALLER_TYPE_SILENT); } } }); final PropertyChangeListener propertyListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (NSISWizardSettings.TARGET_PLATFORM.equals(evt.getPropertyName())) { NSISWizardDialogUtil.populateCombo( instDirCombo, NSISWizardUtil.getPathConstantsAndVariables( ((Integer) evt.getNewValue()).intValue()), ((NSISWizardSettings) evt.getSource()).getInstallDir()); } } }; settings.addPropertyChangeListener(propertyListener); final INSISWizardSettingsListener listener = new INSISWizardSettingsListener() { public void settingsChanged( NSISWizardSettings oldSettings, NSISWizardSettings newSettings) { if (oldSettings != null) { oldSettings.removePropertyChangeListener(propertyListener); } instDirCombo.setText(newSettings.getInstallDir()); changeInstDir.setSelection(newSettings.isChangeInstallDir()); changeInstDir.setEnabled(newSettings.getInstallerType() != INSTALLER_TYPE_SILENT); newSettings.addPropertyChangeListener(propertyListener); } }; mWizard.addSettingsListener(listener); instDirGroup.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { mWizard.removeSettingsListener(listener); mWizard.getSettings().removePropertyChangeListener(propertyListener); } }); }
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("http://wiki.vuze.com/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() { public void mouseDoubleClick(MouseEvent arg0) { Utils.launch((String) ((Label) arg0.widget).getData()); } public void mouseDown(MouseEvent arg0) { Utils.launch((String) ((Label) arg0.widget).getData()); } }); ClipboardCopy.addCopyToClipMenu(linkLabel); final BackupManager backup_manager = BackupManagerFactory.getManager(AzureusCoreFactory.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() { 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() { 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) */ 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); } } }); Label lbl_backup_days = new Label(gDefaultDir, SWT.NULL); Messages.setLanguageText(lbl_backup_days, "br.backup.auto.everydays"); IntParameter backup_everydays = new IntParameter(gDefaultDir, "br.backup.auto.everydays", 1, Integer.MAX_VALUE); gridData = new GridData(); gridData.horizontalSpan = 2; backup_everydays.setLayoutData(gridData); 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() { 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() { 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() { 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() { public boolean reportProgress(String str) { return (append(str, false)); } public void reportComplete() { append("Restore Complete!", true); Utils.execSWTThread( new AERunnable() { 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() { public void prompterClosed(int returnVal) { UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT(); if (uiFunctions != null) { uiFunctions.dispose(true, false); } } }); } }); } 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() { 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); }
public Composite configSectionCreate(final Composite parent) { GridData gridData; Composite cSection = new Composite(parent, SWT.NULL); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL + GridData.VERTICAL_ALIGN_FILL); cSection.setLayoutData(gridData); GridLayout advanced_layout = new GridLayout(); cSection.setLayout(advanced_layout); int userMode = COConfigurationManager.getIntParameter("User Mode"); if (userMode < REQUIRED_MODE) { Label label = new Label(cSection, SWT.WRAP); gridData = new GridData(); label.setLayoutData(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; } new LinkLabel( cSection, gridData, CFG_PREFIX + "info.link", MessageText.getString(CFG_PREFIX + "url")); /////////////////////// ADVANCED SOCKET SETTINGS GROUP ////////// Group gSocket = new Group(cSection, SWT.NULL); Messages.setLanguageText(gSocket, CFG_PREFIX + "socket.group"); gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.FILL_HORIZONTAL); gSocket.setLayoutData(gridData); GridLayout glayout = new GridLayout(); glayout.numColumns = 3; gSocket.setLayout(glayout); // max simultaneous Label lmaxout = new Label(gSocket, SWT.NULL); Messages.setLanguageText( lmaxout, "ConfigView.section.connection.network.max.simultaneous.connect.attempts"); gridData = new GridData(); lmaxout.setLayoutData(gridData); IntParameter max_connects = new IntParameter(gSocket, "network.max.simultaneous.connect.attempts", 1, 100); gridData = new GridData(); gridData.horizontalSpan = 2; max_connects.setLayoutData(gridData); // // max pending Label lmaxpout = new Label(gSocket, SWT.NULL); Messages.setLanguageText( lmaxpout, "ConfigView.section.connection.network.max.outstanding.connect.attempts"); gridData = new GridData(); lmaxpout.setLayoutData(gridData); IntParameter max_pending_connects = new IntParameter(gSocket, "network.tcp.max.connections.outstanding", 1, 65536); gridData = new GridData(); gridData.horizontalSpan = 2; max_pending_connects.setLayoutData(gridData); // bind ip Label lbind = new Label(gSocket, SWT.NULL); Messages.setLanguageText(lbind, "ConfigView.label.bindip"); gridData = new GridData(); lbind.setLayoutData(gridData); StringParameter bindip = new StringParameter(gSocket, "Bind IP", "", false); gridData = new GridData(); gridData.widthHint = 100; gridData.horizontalSpan = 2; bindip.setLayoutData(gridData); Text lbind2 = new Text(gSocket, SWT.READ_ONLY | SWT.MULTI); lbind2.setTabs(8); Messages.setLanguageText( lbind2, "ConfigView.label.bindip.details", new String[] { "\t" + NetworkAdmin.getSingleton() .getNetworkInterfacesAsString() .replaceAll("\\\n", "\n\t") }); gridData = new GridData(); gridData.horizontalSpan = 3; lbind2.setLayoutData(gridData); BooleanParameter check_bind = new BooleanParameter(gSocket, "Check Bind IP On Start", "network.check.ipbinding"); gridData = new GridData(); gridData.horizontalSpan = 3; check_bind.setLayoutData(gridData); BooleanParameter force_bind = new BooleanParameter(gSocket, "Enforce Bind IP", "network.enforce.ipbinding"); gridData = new GridData(); gridData.horizontalSpan = 3; force_bind.setLayoutData(gridData); BooleanParameter bind_icon = new BooleanParameter(gSocket, "Show IP Bindings Icon", "network.ipbinding.icon.show"); gridData = new GridData(); gridData.horizontalSpan = 3; bind_icon.setLayoutData(gridData); Label lpbind = new Label(gSocket, SWT.NULL); Messages.setLanguageText(lpbind, CFG_PREFIX + "bind_port"); final IntParameter port_bind = new IntParameter(gSocket, "network.bind.local.port", 0, 65535); gridData = new GridData(); gridData.horizontalSpan = 2; port_bind.setLayoutData(gridData); Label lmtu = new Label(gSocket, SWT.NULL); Messages.setLanguageText(lmtu, CFG_PREFIX + "mtu"); final IntParameter mtu_size = new IntParameter(gSocket, "network.tcp.mtu.size"); mtu_size.setMaximumValue(512 * 1024); gridData = new GridData(); gridData.horizontalSpan = 2; mtu_size.setLayoutData(gridData); // sndbuf Label lsend = new Label(gSocket, SWT.NULL); Messages.setLanguageText(lsend, CFG_PREFIX + "SO_SNDBUF"); final IntParameter SO_SNDBUF = new IntParameter(gSocket, "network.tcp.socket.SO_SNDBUF"); gridData = new GridData(); SO_SNDBUF.setLayoutData(gridData); final Label lsendcurr = new Label(gSocket, SWT.NULL); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalIndent = 10; lsendcurr.setLayoutData(gridData); // rcvbuf Label lreceiv = new Label(gSocket, SWT.NULL); Messages.setLanguageText(lreceiv, CFG_PREFIX + "SO_RCVBUF"); final IntParameter SO_RCVBUF = new IntParameter(gSocket, "network.tcp.socket.SO_RCVBUF"); gridData = new GridData(); SO_RCVBUF.setLayoutData(gridData); final Label lreccurr = new Label(gSocket, SWT.NULL); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalIndent = 10; lreccurr.setLayoutData(gridData); final Runnable buff_updater = new Runnable() { public void run() { SocketChannel sc = null; int snd_val = 0; int rec_val = 0; try { sc = SocketChannel.open(); Socket socket = sc.socket(); if (SO_SNDBUF.getValue() == 0) { snd_val = socket.getSendBufferSize(); } if (SO_RCVBUF.getValue() == 0) { rec_val = socket.getReceiveBufferSize(); } } catch (Throwable e) { } finally { try { sc.close(); } catch (Throwable e) { } } if (snd_val == 0) { lsendcurr.setText(""); } else { Messages.setLanguageText( lsendcurr, "label.current.equals", new String[] {String.valueOf(snd_val)}); } if (rec_val == 0) { lreccurr.setText(""); } else { Messages.setLanguageText( lreccurr, "label.current.equals", new String[] {String.valueOf(rec_val)}); } } }; buff_updater.run(); ParameterChangeAdapter buff_listener = new ParameterChangeAdapter() { public void parameterChanged(Parameter p, boolean caused_internally) { buff_updater.run(); } }; SO_RCVBUF.addChangeListener(buff_listener); SO_SNDBUF.addChangeListener(buff_listener); Label ltos = new Label(gSocket, SWT.NULL); Messages.setLanguageText(ltos, CFG_PREFIX + "IPDiffServ"); final StringParameter IPDiffServ = new StringParameter(gSocket, "network.tcp.socket.IPDiffServ"); gridData = new GridData(); gridData.widthHint = 100; gridData.horizontalSpan = 2; IPDiffServ.setLayoutData(gridData); // do simple input verification, and registry key setting for TOS field IPDiffServ.addChangeListener( new ParameterChangeAdapter() { final Color obg = IPDiffServ.getControl().getBackground(); final Color ofg = IPDiffServ.getControl().getForeground(); public void parameterChanged(Parameter p, boolean caused_internally) { String raw = IPDiffServ.getValue(); int value = -1; try { value = Integer.decode(raw).intValue(); } catch (Throwable t) { } if (value < 0 || value > 255) { // invalid or no value entered ConfigurationManager.getInstance().removeParameter("network.tcp.socket.IPDiffServ"); if (raw != null && raw.length() > 0) { // error state IPDiffServ.getControl().setBackground(Colors.red); IPDiffServ.getControl().setForeground(Colors.white); } else { // no value state IPDiffServ.getControl().setBackground(obg); IPDiffServ.getControl().setForeground(ofg); } enableTOSRegistrySetting(false); // disable registry setting if necessary } else { // passes test IPDiffServ.getControl().setBackground(obg); IPDiffServ.getControl().setForeground(ofg); enableTOSRegistrySetting(true); // enable registry setting if necessary } } }); // read select Label lreadsel = new Label(gSocket, SWT.NULL); Messages.setLanguageText( lreadsel, CFG_PREFIX + "read_select", new String[] { String.valueOf(COConfigurationManager.getDefault("network.tcp.read.select.time")) }); final IntParameter read_select = new IntParameter(gSocket, "network.tcp.read.select.time", 10, 250); gridData = new GridData(); gridData.horizontalSpan = 2; read_select.setLayoutData(gridData); Label lreadselmin = new Label(gSocket, SWT.NULL); Messages.setLanguageText( lreadselmin, CFG_PREFIX + "read_select_min", new String[] { String.valueOf(COConfigurationManager.getDefault("network.tcp.read.select.min.time")) }); final IntParameter read_select_min = new IntParameter(gSocket, "network.tcp.read.select.min.time", 0, 100); gridData = new GridData(); gridData.horizontalSpan = 2; read_select_min.setLayoutData(gridData); // write select Label lwritesel = new Label(gSocket, SWT.NULL); Messages.setLanguageText( lwritesel, CFG_PREFIX + "write_select", new String[] { String.valueOf(COConfigurationManager.getDefault("network.tcp.write.select.time")) }); final IntParameter write_select = new IntParameter(gSocket, "network.tcp.write.select.time", 10, 250); gridData = new GridData(); gridData.horizontalSpan = 2; write_select.setLayoutData(gridData); Label lwriteselmin = new Label(gSocket, SWT.NULL); Messages.setLanguageText( lwriteselmin, CFG_PREFIX + "write_select_min", new String[] { String.valueOf(COConfigurationManager.getDefault("network.tcp.write.select.min.time")) }); final IntParameter write_select_min = new IntParameter(gSocket, "network.tcp.write.select.min.time", 0, 100); gridData = new GridData(); gridData.horizontalSpan = 2; write_select_min.setLayoutData(gridData); new BooleanParameter(cSection, "IPV6 Enable Support", "network.ipv6.enable.support"); new BooleanParameter(cSection, "IPV6 Prefer Addresses", "network.ipv6.prefer.addresses"); if (Constants.isWindowsVistaOrHigher && Constants.isJava7OrHigher) { new BooleanParameter(cSection, "IPV4 Prefer Stack", "network.ipv4.prefer.stack"); } ////////////////////////////////////////////////////////////////////////// return cSection; }
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout()); GLData data = new GLData(); data.doubleBuffer = true; final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data); canvas.setCurrent(); try { GLContext.useContext(canvas); } catch (LWJGLException e) { e.printStackTrace(); } canvas.addListener( SWT.Resize, event -> { Rectangle bounds = canvas.getBounds(); float fAspect = (float) bounds.width / (float) bounds.height; canvas.setCurrent(); try { GLContext.useContext(canvas); } catch (LWJGLException e) { e.printStackTrace(); } GL11.glViewport(0, 0, bounds.width, bounds.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); }); GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glClearDepth(1.0); GL11.glLineWidth(2); GL11.glEnable(GL11.GL_DEPTH_TEST); shell.setText("SWT/LWJGL Example"); shell.setSize(640, 480); shell.open(); final Runnable run = new Runnable() { int rot = 0; @Override public void run() { if (!canvas.isDisposed()) { canvas.setCurrent(); try { GLContext.useContext(canvas); } catch (LWJGLException e) { e.printStackTrace(); } GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glClearColor(.3f, .5f, .8f, 1.0f); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -10.0f); float frot = rot; GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); rot++; GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); GL11.glColor3f(0.9f, 0.9f, 0.9f); drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15); canvas.swapBuffers(); display.asyncExec(this); } } }; canvas.addListener(SWT.Paint, event -> run.run()); display.asyncExec(run); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
/* * (non-Javadoc) * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) */ public void createControl(Composite parent) { display = parent.getDisplay(); sashForm = new SashForm(parent, SWT.VERTICAL); FillLayout layout = new FillLayout(); sashForm.setLayout(layout); GridData data = new GridData(GridData.FILL_BOTH); sashForm.setLayoutData(data); initializeDialogUnits(sashForm); Composite composite = new Composite(sashForm, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; composite.setLayout(gridLayout); treeViewer = createTreeViewer(composite); data = new GridData(GridData.FILL_BOTH); data.heightHint = convertHeightInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_HEIGHT); data.widthHint = convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH); Tree tree = treeViewer.getTree(); tree.setLayoutData(data); tree.setHeaderVisible(true); activateCopy(tree); TreeViewerColumn nameColumn = new TreeViewerColumn(treeViewer, SWT.LEFT); nameColumn.getColumn().setText(ProvUIMessages.ProvUI_NameColumnTitle); nameColumn.getColumn().setWidth(400); nameColumn.getColumn().setMoveable(true); nameColumn.setLabelProvider( new ColumnLabelProvider() { public String getText(Object element) { IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class); String label = iu.getProperty(IInstallableUnit.PROP_NAME, null); if (label == null) label = iu.getId(); return label; } public Image getImage(Object element) { if (element instanceof ProvElement) return ((ProvElement) element).getImage(element); if (ProvUI.getAdapter(element, IInstallableUnit.class) != null) return ProvUIImages.getImage(ProvUIImages.IMG_IU); return null; } public String getToolTipText(Object element) { if (element instanceof AvailableIUElement && ((AvailableIUElement) element).getImageOverlayId(null) == ProvUIImages.IMG_INFO) return ProvUIMessages.RemedyElementNotHighestVersion; return super.getToolTipText(element); } }); TreeViewerColumn versionColumn = new TreeViewerColumn(treeViewer, SWT.LEFT); versionColumn.getColumn().setText(ProvUIMessages.ProvUI_VersionColumnTitle); versionColumn.getColumn().setWidth(200); versionColumn.setLabelProvider( new ColumnLabelProvider() { public String getText(Object element) { IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class); if (element instanceof IIUElement) { if (((IIUElement) element).shouldShowVersion()) return iu.getVersion().toString(); return ""; //$NON-NLS-1$ } return iu.getVersion().toString(); } }); TreeViewerColumn idColumn = new TreeViewerColumn(treeViewer, SWT.LEFT); idColumn.getColumn().setText(ProvUIMessages.ProvUI_IdColumnTitle); idColumn.getColumn().setWidth(200); idColumn.setLabelProvider( new ColumnLabelProvider() { public String getText(Object element) { IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class); return iu.getId(); } }); // Filters and sorters before establishing content, so we don't refresh unnecessarily. IUComparator comparator = new IUComparator(IUComparator.IU_NAME); comparator.useColumnConfig(getColumnConfig()); treeViewer.setComparator(comparator); treeViewer.setComparer(new ProvElementComparer()); ColumnViewerToolTipSupport.enableFor(treeViewer); contentProvider = new ProvElementContentProvider(); treeViewer.setContentProvider(contentProvider); // labelProvider = new IUDetailsLabelProvider(null, getColumnConfig(), getShell()); // treeViewer.setLabelProvider(labelProvider); // Optional area to show the size createSizingInfo(composite); // The text area shows a description of the selected IU, or error detail if applicable. iuDetailsGroup = new IUDetailsGroup( sashForm, treeViewer, convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH), true); setControl(sashForm); sashForm.setWeights(getSashWeights()); Dialog.applyDialogFont(sashForm); // Controls for filtering/presentation/site selection Composite controlsComposite = new Composite(composite, SWT.NONE); gridLayout = new GridLayout(); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; gridLayout.numColumns = 2; gridLayout.makeColumnsEqualWidth = true; gridLayout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); controlsComposite.setLayout(layout); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false); controlsComposite.setLayoutData(gd); final Runnable runnable = new Runnable() { public void run() { treeViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { setDetailText(resolvedOperation); } }); setDrilldownElements(input, resolvedOperation); treeViewer.setInput(input); } }; if (resolvedOperation != null && !resolvedOperation.hasResolved()) { try { getContainer() .run( true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { resolvedOperation.resolveModal(monitor); display.asyncExec(runnable); } }); } catch (Exception e) { StatusManager.getManager() .handle(new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, e.getMessage(), e)); } } else { runnable.run(); } }