Search in sources :

Example 26 with RowData

use of org.eclipse.swt.layout.RowData in project cubrid-manager by CUBRID.

the class HAPropertyPage method createHostUserGroup.

/**
	 * 
	 * Create diagnostics group composite
	 * 
	 * @param parent the parent composite
	 */
private void createHostUserGroup(Composite parent) {
    Group hostUserGroup = new Group(parent, SWT.NONE);
    hostUserGroup.setText(Messages.grpHAHostUser);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    hostUserGroup.setLayoutData(gridData);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    hostUserGroup.setLayout(layout);
    Label hostNameLabel = new Label(hostUserGroup, SWT.LEFT);
    hostNameLabel.setText(Messages.lblHostName);
    hostNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    hostNameText = new Text(hostUserGroup, SWT.LEFT | SWT.BORDER);
    hostNameText.setEnabled(isAdmin);
    hostNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    Label userNameLabel = new Label(hostUserGroup, SWT.LEFT);
    userNameLabel.setText(Messages.lblUserName);
    userNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    userNameText = new Text(hostUserGroup, SWT.LEFT | SWT.BORDER);
    userNameText.setToolTipText(Messages.tipUserName);
    userNameText.setEnabled(isAdmin);
    userNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    Label haCopySyncModeLabel = new Label(hostUserGroup, SWT.LEFT);
    haCopySyncModeLabel.setText(Messages.lblHACopySyncMode);
    haCopySyncModeLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    userHaCopySyncModeText = new Text(hostUserGroup, SWT.LEFT | SWT.BORDER);
    userHaCopySyncModeText.setToolTipText(Messages.tipSyncMode);
    userHaCopySyncModeText.setEnabled(isAdmin);
    userHaCopySyncModeText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    Composite btnComposite = createBtnComposite(hostUserGroup);
    Button addBtn = new Button(btnComposite, SWT.NONE);
    RowData rowData = new RowData();
    rowData.width = 60;
    addBtn.setLayoutData(rowData);
    addBtn.setText(Messages.btnAdd);
    addBtn.setEnabled(isAdmin);
    addBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            String hostName = hostNameText.getText();
            String userName = userNameText.getText();
            String syncMode = userHaCopySyncModeText.getText();
            if (hostName.trim().length() == 0) {
                CommonUITool.openErrorBox(Messages.errHostName);
                hostNameText.setFocus();
                return;
            }
            if (userName.trim().length() == 0) {
                CommonUITool.openErrorBox(Messages.errUserName);
                userNameText.setFocus();
                return;
            }
            if (syncMode.trim().length() == 0) {
                CommonUITool.openErrorBox(Messages.errSyncMode);
                userHaCopySyncModeText.setFocus();
                return;
            }
            TableItem[] items = hostUserTable.getItems();
            TableItem editItem = null;
            for (int i = 0; i < items.length; i++) {
                TableItem item = items[i];
                if (hostName.equals(item.getText(0)) && userName.equals(item.getText(1))) {
                    editItem = item;
                    break;
                }
            }
            if (editItem == null) {
                editItem = new TableItem(hostUserTable, SWT.NONE);
            }
            editItem.setText(0, hostName);
            editItem.setText(1, userName);
            editItem.setText(2, syncMode);
        }
    });
    hostUserTable = new Table(hostUserGroup, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    {
        hostUserTable.setHeaderVisible(true);
        GridData gdColumnTable = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
        gdColumnTable.heightHint = 160;
        hostUserTable.setLayoutData(gdColumnTable);
        hostUserTable.setLinesVisible(true);
    }
    CommonUITool.hackForYosemite(hostUserTable);
    hostUserTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            TableItem[] items = hostUserTable.getSelection();
            if (items == null || items.length == 0) {
                delBtn.setEnabled(false);
            } else {
                delBtn.setEnabled(isAdmin);
            }
            if (isAdmin && items != null && items.length > 0) {
                String hostName = items[0].getText(0);
                String userName = items[0].getText(1);
                String syncMode = items[0].getText(2);
                hostNameText.setText(hostName);
                userNameText.setText(userName);
                userHaCopySyncModeText.setText(syncMode);
            }
        }
    });
    TableColumn tblCol = new TableColumn(hostUserTable, SWT.LEFT);
    tblCol.setWidth(83);
    tblCol.setText(Messages.colHostName);
    tblCol = new TableColumn(hostUserTable, SWT.LEFT);
    tblCol.setWidth(123);
    tblCol.setText(Messages.colUserName);
    tblCol = new TableColumn(hostUserTable, SWT.LEFT);
    tblCol.setWidth(196);
    tblCol.setText(Messages.colHACopySyncMode);
    btnComposite = createBtnComposite(hostUserGroup);
    delBtn = new Button(btnComposite, SWT.NONE);
    rowData = new RowData();
    rowData.width = 60;
    delBtn.setLayoutData(rowData);
    delBtn.setText(Messages.btnDelete);
    delBtn.setEnabled(isAdmin);
    delBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            int[] indices = hostUserTable.getSelectionIndices();
            if (indices == null || indices.length == 0) {
                return;
            }
            hostUserTable.remove(indices);
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 27 with RowData

use of org.eclipse.swt.layout.RowData in project eclipse.platform.swt by eclipse.

the class RowLayoutTab method setLayoutData.

/**
 * Sets the layout data for the children of the layout.
 */
@Override
void setLayoutData() {
    Control[] children = layoutComposite.getChildren();
    TableItem[] items = table.getItems();
    RowData data;
    int width, height;
    String exclude;
    for (int i = 0; i < children.length; i++) {
        width = Integer.valueOf(items[i].getText(WIDTH_COL)).intValue();
        height = Integer.valueOf(items[i].getText(HEIGHT_COL)).intValue();
        data = new RowData(width, height);
        exclude = items[i].getText(EXCLUDE_COL);
        data.exclude = exclude.equals("true");
        children[i].setLayoutData(data);
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) RowData(org.eclipse.swt.layout.RowData) TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point)

Example 28 with RowData

use of org.eclipse.swt.layout.RowData in project erlide_eclipse by erlang.

the class ControlPanelView method createPatternButtonsPanel.

private void createPatternButtonsPanel(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new RowLayout());
    // "Add" button
    Button button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("New pattern");
    button.setToolTipText("Add new trace pattern");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            TraceBackend.getInstance().addTracePattern(new TracePattern(true));
        }
    });
    // "Remove" button
    button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("Remove pattern");
    button.setToolTipText("Remove selected trace pattern");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final TracePattern tracePattern = (TracePattern) ((IStructuredSelection) functionsTableViewer.getSelection()).getFirstElement();
            if (tracePattern != null) {
                TraceBackend.getInstance().removeTracePattern(tracePattern);
            }
        }
    });
    // Pattern config buttons
    final Button loadConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button deleteConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button saveConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button saveAsConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Label configNameLabel = new Label(container, SWT.NULL);
    configNameLabel.setLayoutData(new RowData(120, SWT.DEFAULT));
    // "Load patterns" button
    loadConfigButton.setToolTipText("Load pattern set...");
    loadConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
    loadConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final ElementListSelectionDialog dialog = new SelectConfigurationDialog(parent.getShell(), new LabelProvider());
            dialog.setElements(ConfigurationManager.getTPConfigs());
            dialog.open();
            final String result = (String) dialog.getFirstResult();
            if (result != null) {
                patternsConfigName = result;
                configNameLabel.setText(patternsConfigName);
                TraceBackend.getInstance().loadTracePatterns(ConfigurationManager.loadTPConfig(patternsConfigName));
            }
        }
    });
    // "Delete patterns" button
    deleteConfigButton.setToolTipText("Delete current pattern set...");
    deleteConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_REMOVE));
    deleteConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (patternsConfigName != null) {
                final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
                messageBox.setMessage("Delete \"" + patternsConfigName + "\"?");
                messageBox.setText("Delete configuration");
                if (messageBox.open() == SWT.YES) {
                    ConfigurationManager.removeTPConfig(patternsConfigName);
                    patternsConfigName = null;
                    configNameLabel.setText("");
                }
            }
        }
    });
    // "Save patterns" button
    saveConfigButton.setToolTipText("Save current pattern set");
    saveConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVE_EDIT));
    saveConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (patternsConfigName != null) {
                if (!ConfigurationManager.saveTPConfig(patternsConfigName)) {
                    final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
                    messageBox.setMessage("Unable to save configuration: " + patternsConfigName);
                    messageBox.setText("Error");
                    messageBox.open();
                }
            }
        }
    });
    // "Save patterns as..." button
    saveAsConfigButton.setToolTipText("Save current pattern set as...");
    saveAsConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVEAS_EDIT));
    saveAsConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final String[] configurations = ConfigurationManager.getTPConfigs();
            final Set<String> existingNames = new HashSet<>(Arrays.asList(configurations));
            final InputDialog dialog = new ConfigurationSaveAsDialog(parent.getShell(), "Save trace pattern configuration", "Enter name for configuration:", patternsConfigName, existingNames);
            if (dialog.open() == Window.OK) {
                if (ConfigurationManager.saveTPConfig(dialog.getValue())) {
                    patternsConfigName = dialog.getValue();
                    configNameLabel.setText(patternsConfigName);
                } else {
                    final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
                    messageBox.setMessage("Unable to save configuration: " + dialog.getValue());
                    messageBox.setText("Error");
                    messageBox.open();
                }
            }
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectConfigurationDialog(org.erlide.tracing.core.ui.dialogs.SelectConfigurationDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ConfigurationSaveAsDialog(org.erlide.tracing.core.ui.dialogs.ConfigurationSaveAsDialog) NodeLabelProvider(org.erlide.tracing.core.mvc.view.NodeLabelProvider) TracePatternLabelProvider(org.erlide.tracing.core.mvc.view.TracePatternLabelProvider) ProcessLabelProvider(org.erlide.tracing.core.mvc.view.ProcessLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TracePattern(org.erlide.tracing.core.mvc.model.TracePattern)

Example 29 with RowData

use of org.eclipse.swt.layout.RowData in project erlide_eclipse by erlang.

the class ControlPanelView method createNodeButtonsPanel.

private void createNodeButtonsPanel(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new RowLayout());
    // "Add" button
    Button button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("New node");
    button.setToolTipText("Add new node you want to trace");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            TraceBackend.getInstance().addTracedNode(new TracedNode());
            nodesTableViewer.refresh();
        }
    });
    // "Remove" button
    button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("Remove node");
    button.setToolTipText("Remove selected node");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final TracedNode tracedNode = (TracedNode) ((IStructuredSelection) nodesTableViewer.getSelection()).getFirstElement();
            if (tracedNode != null) {
                TraceBackend.getInstance().removeTracedNode(tracedNode);
                nodesTableViewer.refresh();
            }
        }
    });
    // "Add erlide nodes" button
    button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("Add existing nodes");
    button.setToolTipText("Add all Erlang nodes started directly from eclipse");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            for (final IBackend backend : NodeHelper.getBackends(true)) {
                final TracedNode node = new TracedNode();
                node.setNodeName(backend.getName());
                TraceBackend.getInstance().addTracedNode(node);
            }
            nodesTableViewer.refresh();
        }
    });
    // Pattern config buttons
    final Button loadConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button deleteConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button saveConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button saveAsConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Label configNameLabel = new Label(container, SWT.NULL);
    configNameLabel.setLayoutData(new RowData(120, SWT.DEFAULT));
    // "Load nodes config" button
    loadConfigButton.setToolTipText("Load nodes configuration...");
    loadConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
    loadConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final ElementListSelectionDialog dialog = new SelectConfigurationDialog(parent.getShell(), new LabelProvider());
            dialog.setElements(ConfigurationManager.getNodesConfig());
            dialog.open();
            final String result = (String) dialog.getFirstResult();
            if (result != null) {
                nodesConfigName = result;
                configNameLabel.setText(nodesConfigName);
                TraceBackend.getInstance().loadTracedNodes(ConfigurationManager.loadNodesConfig(nodesConfigName));
                nodesTableViewer.refresh();
            }
        }
    });
    // "Delete nodes configuration" button
    deleteConfigButton.setToolTipText("Delete current node configuration...");
    deleteConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_REMOVE));
    deleteConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (nodesConfigName != null) {
                final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
                messageBox.setMessage("Delete \"" + nodesConfigName + "\"?");
                messageBox.setText("Delete configuration");
                if (messageBox.open() == SWT.YES) {
                    ConfigurationManager.removeNodesConfig(nodesConfigName);
                    nodesConfigName = null;
                    configNameLabel.setText("");
                }
            }
        }
    });
    // "Save nodes configuration" button
    saveConfigButton.setToolTipText("Save current nodes configuration");
    saveConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVE_EDIT));
    saveConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (nodesConfigName != null) {
                if (!ConfigurationManager.saveNodesConfig(nodesConfigName)) {
                    final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
                    messageBox.setMessage("Unable to save configuration: " + nodesConfigName);
                    messageBox.setText("Error");
                    messageBox.open();
                }
            }
        }
    });
    // "Save nodes configuration as..." button
    saveAsConfigButton.setToolTipText("Save current nodes configuration as...");
    saveAsConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVEAS_EDIT));
    saveAsConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final String[] configurations = ConfigurationManager.getNodesConfig();
            final Set<String> existingNames = new HashSet<>(Arrays.asList(configurations));
            final InputDialog dialog = new ConfigurationSaveAsDialog(parent.getShell(), "Save nodes configuration", "Enter name for configuration:", nodesConfigName, existingNames);
            if (dialog.open() == Window.OK) {
                if (ConfigurationManager.saveNodesConfig(dialog.getValue())) {
                    nodesConfigName = dialog.getValue();
                    configNameLabel.setText(nodesConfigName);
                } else {
                    final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
                    messageBox.setMessage("Unable to save configuration: " + dialog.getValue());
                    messageBox.setText("Error");
                    messageBox.open();
                }
            }
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TracedNode(org.erlide.tracing.core.mvc.model.TracedNode) SelectConfigurationDialog(org.erlide.tracing.core.ui.dialogs.SelectConfigurationDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) RowLayout(org.eclipse.swt.layout.RowLayout) IBackend(org.erlide.backend.api.IBackend) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ConfigurationSaveAsDialog(org.erlide.tracing.core.ui.dialogs.ConfigurationSaveAsDialog) NodeLabelProvider(org.erlide.tracing.core.mvc.view.NodeLabelProvider) TracePatternLabelProvider(org.erlide.tracing.core.mvc.view.TracePatternLabelProvider) ProcessLabelProvider(org.erlide.tracing.core.mvc.view.ProcessLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 30 with RowData

use of org.eclipse.swt.layout.RowData in project BiglyBT by BiglySoftware.

the class MyTorrentsView method buildCatAndTag.

/**
 * @since 3.1.1.1
 */
private void buildCatAndTag(List<Tag> tags) {
    if (tags.size() == 0 || cCategoriesAndTags.isDisposed()) {
        return;
    }
    int iFontPixelsHeight = Utils.adjustPXForDPI(10);
    int iFontPointHeight = (iFontPixelsHeight * 72) / Utils.getDPIRaw(cCategoriesAndTags.getDisplay()).y;
    Label spacer = null;
    int max_rd_height = 0;
    allTags = tags;
    if (buttonListener == null) {
        buttonListener = new Listener() {

            boolean bDownPressed;

            private TimerEvent timerEvent;

            @Override
            public void handleEvent(Event event) {
                Button curButton = (Button) event.widget;
                if (event.type == SWT.MouseDown) {
                    if (timerEvent == null) {
                        timerEvent = SimpleTimer.addEvent("MouseHold", SystemTime.getOffsetTime(1000), new TimerEventPerformer() {

                            @Override
                            public void perform(TimerEvent te) {
                                timerEvent = null;
                                if (!bDownPressed) {
                                    return;
                                }
                                bDownPressed = false;
                                // held
                                Utils.execSWTThread(new Runnable() {

                                    public void run() {
                                        Object[] ds = tv.getSelectedDataSources().toArray();
                                        Tag tag = (Tag) curButton.getData("Tag");
                                        if (tag instanceof Category) {
                                            TorrentUtil.assignToCategory(ds, (Category) tag);
                                            return;
                                        }
                                        boolean doAdd = false;
                                        for (Object obj : ds) {
                                            if (obj instanceof DownloadManager) {
                                                DownloadManager dm = (DownloadManager) obj;
                                                if (!tag.hasTaggable(dm)) {
                                                    doAdd = true;
                                                    break;
                                                }
                                            }
                                        }
                                        for (Object obj : ds) {
                                            if (obj instanceof DownloadManager) {
                                                DownloadManager dm = (DownloadManager) obj;
                                                if (doAdd) {
                                                    tag.addTaggable(dm);
                                                } else {
                                                    tag.removeTaggable(dm);
                                                }
                                            }
                                        }
                                        setSelection(curButton.getParent());
                                        curButton.setEnabled(false);
                                        SimpleTimer.addEvent("ButtonEnable", SystemTime.getOffsetTime(10), new TimerEventPerformer() {

                                            @Override
                                            public void perform(TimerEvent te) {
                                                Utils.execSWTThread(new Runnable() {

                                                    public void run() {
                                                        curButton.setEnabled(true);
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                    bDownPressed = true;
                    return;
                } else {
                    if (timerEvent != null) {
                        timerEvent.cancel();
                        timerEvent = null;
                    }
                    if (!bDownPressed) {
                        setSelection(curButton.getParent());
                        return;
                    }
                }
                bDownPressed = false;
                boolean add = (event.stateMask & SWT.MOD1) != 0;
                boolean isEnabled = curButton.getSelection();
                Tag tag = (Tag) curButton.getData("Tag");
                if (!isEnabled) {
                    removeTagFromCurrent(tag);
                } else {
                    if (add) {
                        Category catAll = CategoryManager.getCategory(Category.TYPE_ALL);
                        if (tag.equals(catAll)) {
                            setCurrentTags(new Tag[] { catAll });
                        } else {
                            Tag[] newTags = new Tag[currentTags.length + 1];
                            System.arraycopy(currentTags, 0, newTags, 0, currentTags.length);
                            newTags[currentTags.length] = tag;
                            newTags = (Tag[]) removeFromArray(newTags, catAll);
                            setCurrentTags(newTags);
                        }
                    } else {
                        setCurrentTags(new Tag[] { (Tag) curButton.getData("Tag") });
                    }
                }
                setSelection(curButton.getParent());
            }

            private void setSelection(Composite parent) {
                Control[] controls = parent.getChildren();
                for (int i = 0; i < controls.length; i++) {
                    if (!(controls[i] instanceof Button)) {
                        continue;
                    }
                    Button b = (Button) controls[i];
                    Tag btag = (Tag) b.getData("Tag");
                    b.setSelection(isCurrent(btag));
                }
            }
        };
        buttonHoverListener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                Button curButton = (Button) event.widget;
                Tag tag = (Tag) curButton.getData("Tag");
                if (!(tag instanceof Category)) {
                    curButton.setToolTipText(TagUIUtils.getTagTooltip(tag, true));
                    return;
                }
                Category category = (Category) tag;
                List<DownloadManager> dms = category.getDownloadManagers(globalManager.getDownloadManagers());
                long ttlActive = 0;
                long ttlSize = 0;
                long ttlRSpeed = 0;
                long ttlSSpeed = 0;
                int count = 0;
                for (DownloadManager dm : dms) {
                    if (!category.hasTaggable(dm)) {
                        continue;
                    }
                    count++;
                    if (dm.getState() == DownloadManager.STATE_DOWNLOADING || dm.getState() == DownloadManager.STATE_SEEDING) {
                        ttlActive++;
                    }
                    DownloadManagerStats stats = dm.getStats();
                    ttlSize += stats.getSizeExcludingDND();
                    ttlRSpeed += stats.getDataReceiveRate();
                    ttlSSpeed += stats.getDataSendRate();
                }
                String up_details = "";
                String down_details = "";
                if (category.getType() != Category.TYPE_ALL) {
                    String up_str = MessageText.getString("GeneralView.label.maxuploadspeed");
                    String down_str = MessageText.getString("GeneralView.label.maxdownloadspeed");
                    String unlimited_str = MessageText.getString("MyTorrentsView.menu.setSpeed.unlimited");
                    int up_speed = category.getUploadSpeed();
                    int down_speed = category.getDownloadSpeed();
                    up_details = up_str + ": " + (up_speed == 0 ? unlimited_str : DisplayFormatters.formatByteCountToKiBEtc(up_speed));
                    down_details = down_str + ": " + (down_speed == 0 ? unlimited_str : DisplayFormatters.formatByteCountToKiBEtc(down_speed));
                }
                if (count == 0) {
                    curButton.setToolTipText(down_details + "\n" + up_details + "\nTotal: 0");
                    return;
                }
                curButton.setToolTipText((up_details.length() == 0 ? "" : (down_details + "\n" + up_details + "\n")) + "Total: " + count + "\n" + "Downloading/Seeding: " + ttlActive + "\n" + "\n" + "Total Speed: " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlRSpeed) + " / " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlSSpeed) + "\n" + "Average Speed: " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlRSpeed / (ttlActive == 0 ? 1 : ttlActive)) + " / " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlSSpeed / (ttlActive == 0 ? 1 : ttlActive)) + "\n" + "Size: " + DisplayFormatters.formatByteCountToKiBEtc(ttlSize));
            }
        };
        buttonDropTargetListener = new DropTargetAdapter() {

            @Override
            public void dragOver(DropTargetEvent e) {
                if (drag_drop_line_start >= 0) {
                    boolean doAdd = false;
                    Control curButton = ((DropTarget) e.widget).getControl();
                    Tag tag = (Tag) curButton.getData("Tag");
                    Object[] ds = tv.getSelectedDataSources().toArray();
                    if (tag != null) {
                        for (Object obj : ds) {
                            if (obj instanceof DownloadManager) {
                                DownloadManager dm = (DownloadManager) obj;
                                if (!tag.hasTaggable(dm)) {
                                    doAdd = true;
                                    break;
                                }
                            }
                        }
                    }
                    e.detail = doAdd ? DND.DROP_COPY : DND.DROP_MOVE;
                } else {
                    e.detail = DND.DROP_NONE;
                }
            }

            @Override
            public void drop(DropTargetEvent e) {
                e.detail = DND.DROP_NONE;
                if (drag_drop_line_start >= 0) {
                    drag_drop_line_start = -1;
                    drag_drop_rows = null;
                    Object[] ds = tv.getSelectedDataSources().toArray();
                    Control curButton = ((DropTarget) e.widget).getControl();
                    Tag tag = (Tag) curButton.getData("Tag");
                    if (tag instanceof Category) {
                        TorrentUtil.assignToCategory(ds, (Category) tag);
                        return;
                    }
                    boolean doAdd = false;
                    for (Object obj : ds) {
                        if (obj instanceof DownloadManager) {
                            DownloadManager dm = (DownloadManager) obj;
                            if (!tag.hasTaggable(dm)) {
                                doAdd = true;
                                break;
                            }
                        }
                    }
                    for (Object obj : ds) {
                        if (obj instanceof DownloadManager) {
                            DownloadManager dm = (DownloadManager) obj;
                            if (doAdd) {
                                tag.addTaggable(dm);
                            } else {
                                tag.removeTaggable(dm);
                            }
                        }
                    }
                }
            }
        };
    }
    for (final Tag tag : tags) {
        boolean isCat = (tag instanceof Category);
        final Button button = new Button(cCategoriesAndTags, SWT.TOGGLE);
        if (isCat) {
            if (spacer == null) {
                spacer = new Label(cCategoriesAndTags, SWT.NONE);
                RowData rd = new RowData();
                rd.width = 8;
                spacer.setLayoutData(rd);
                spacer.moveAbove(null);
            }
            button.moveAbove(spacer);
        }
        button.addKeyListener(this);
        if (fontButton == null) {
            Font f = button.getFont();
            FontData fd = f.getFontData()[0];
            fd.setHeight(iFontPointHeight);
            fontButton = new Font(cCategoriesAndTags.getDisplay(), fd);
        }
        button.setText("|");
        button.setFont(fontButton);
        button.pack(true);
        if (button.computeSize(100, SWT.DEFAULT).y > 0) {
            RowData rd = new RowData();
            int rd_height = button.computeSize(100, SWT.DEFAULT).y - 2 + button.getBorderWidth() * 2;
            rd.height = rd_height;
            max_rd_height = Math.max(max_rd_height, rd_height);
            button.setLayoutData(rd);
        }
        String tag_name = tag.getTagName(true);
        button.setText(tag_name);
        button.setData("Tag", tag);
        if (isCurrent(tag)) {
            button.setSelection(true);
        }
        button.addListener(SWT.MouseUp, buttonListener);
        button.addListener(SWT.MouseDown, buttonListener);
        button.addListener(SWT.MouseHover, buttonHoverListener);
        final DropTarget tabDropTarget = new DropTarget(button, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
        Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
        tabDropTarget.setTransfer(types);
        tabDropTarget.addDropListener(buttonDropTargetListener);
        button.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (!tabDropTarget.isDisposed()) {
                    tabDropTarget.dispose();
                }
            }
        });
        Menu menu = new Menu(button);
        button.setMenu(menu);
        if (isCat) {
            CategoryUIUtils.setupCategoryMenu(menu, (Category) tag);
        } else {
            TagUIUtils.createSideBarMenuItems(menu, tag);
        }
    }
    if (max_rd_height > 0) {
        RowLayout layout = (RowLayout) cCategoriesAndTags.getLayout();
        int top_margin = (24 - max_rd_height + 1) / 2;
        if (top_margin > 0) {
            layout.marginTop = top_margin;
        }
    }
    cCategoriesAndTags.getParent().layout(true, true);
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) DownloadManagerListener(com.biglybt.core.download.DownloadManagerListener) UIToolBarActivationListener(com.biglybt.pif.ui.toolbar.UIToolBarActivationListener) GlobalManagerListener(com.biglybt.core.global.GlobalManagerListener) TableRowRefreshListener(com.biglybt.pif.ui.tables.TableRowRefreshListener) GlobalManagerEventListener(com.biglybt.core.global.GlobalManagerEventListener) Category(com.biglybt.core.category.Category) DownloadManager(com.biglybt.core.download.DownloadManager) RowData(org.eclipse.swt.layout.RowData) RowLayout(org.eclipse.swt.layout.RowLayout) List(java.util.List) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) FixedURLTransfer(com.biglybt.ui.swt.FixedURLTransfer) GlobalManagerEvent(com.biglybt.core.global.GlobalManagerEvent) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) LogEvent(com.biglybt.core.logging.LogEvent)

Aggregations

RowData (org.eclipse.swt.layout.RowData)55 RowLayout (org.eclipse.swt.layout.RowLayout)52 Composite (org.eclipse.swt.widgets.Composite)48 Button (org.eclipse.swt.widgets.Button)45 GridData (org.eclipse.swt.layout.GridData)44 SelectionEvent (org.eclipse.swt.events.SelectionEvent)43 GridLayout (org.eclipse.swt.layout.GridLayout)40 SelectionListener (org.eclipse.swt.events.SelectionListener)33 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)26 Label (org.eclipse.swt.widgets.Label)26 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)25 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)25 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)21 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)21 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)20 Event (org.eclipse.swt.widgets.Event)15 TableViewer (org.eclipse.jface.viewers.TableViewer)12 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 Text (org.eclipse.swt.widgets.Text)11