Search in sources :

Example 31 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project statecharts by Yakindu.

the class ExampleDropTargetListener method drop.

@Override
public void drop(DropTargetEvent event) {
    if (!URLTransfer.getInstance().isSupportedType(event.currentDataType)) {
        return;
    }
    final String url = getUrl(event.data);
    if (ExampleURLHandler.isValidExample(url)) {
        DropTarget source = (DropTarget) event.getSource();
        Display display = source.getDisplay();
        display.asyncExec(new Runnable() {

            public void run() {
                proceedInstallation(url);
            }
        });
    }
}
Also used : DropTarget(org.eclipse.swt.dnd.DropTarget) Display(org.eclipse.swt.widgets.Display)

Example 32 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project portfolio by buchen.

the class DashboardView method addDropListener.

private void addDropListener(Composite parent) {
    LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
    DropTargetAdapter dragAdapter = new WidgetDropTargetAdapter(transfer, parent, w -> markDirty());
    DropTarget dropTarget = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY);
    dropTarget.setTransfer(new Transfer[] { transfer });
    dropTarget.addDropListener(dragAdapter);
}
Also used : DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) DropTarget(org.eclipse.swt.dnd.DropTarget) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer)

Example 33 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project BiglyBT by BiglySoftware.

the class BuddyPluginViewBetaChat method buildStatus.

private void buildStatus(Composite main_component, Composite component) {
    boolean public_chat = !chat.isPrivateChat();
    final Label menu_drop = new Label(component, SWT.NULL);
    Messages.setLanguageTooltip(menu_drop, "TagSettingsView.title");
    FontData fontData = menu_drop.getFont().getFontData()[0];
    Display display = menu_drop.getDisplay();
    italic_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.ITALIC));
    bold_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
    big_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 1.5), SWT.BOLD));
    small_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 0.5), SWT.BOLD));
    ftux_dark_bg = new Color(display, 183, 200, 212);
    ftux_dark_fg = new Color(display, 0, 81, 134);
    ftux_light_bg = new Color(display, 236, 242, 246);
    component.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent arg0) {
            Font[] fonts = { italic_font, bold_font, big_font, small_font };
            for (Font f : fonts) {
                if (f != null) {
                    f.dispose();
                }
            }
            Color[] colours = { ftux_dark_bg, ftux_dark_fg, ftux_light_bg };
            for (Color c : colours) {
                if (c != null) {
                    c.dispose();
                }
            }
            if (drop_targets != null) {
                for (DropTarget dt : drop_targets) {
                    dt.dispose();
                }
            }
            closed();
        }
    });
    status = new BufferedLabel(component, SWT.LEFT | SWT.DOUBLE_BUFFERED);
    GridData grid_data = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(status, grid_data);
    status.setText(MessageText.getString("PeersView.state.pending"));
    Image image = ImageLoader.getInstance().getImage("cog_down");
    menu_drop.setImage(image);
    grid_data = new GridData();
    grid_data.widthHint = image.getBounds().width;
    grid_data.heightHint = image.getBounds().height;
    Utils.setLayoutData(menu_drop, grid_data);
    menu_drop.setCursor(menu_drop.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    Control status_control = status.getControl();
    final Menu status_menu = new Menu(status_control);
    status.getControl().setMenu(status_menu);
    menu_drop.setMenu(status_menu);
    menu_drop.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent event) {
            try {
                Point p = status_menu.getDisplay().map(menu_drop, null, event.x, event.y);
                status_menu.setLocation(p);
                status_menu.setVisible(true);
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    });
    if (public_chat) {
        Menu status_clip_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
        MenuItem status_clip_item = new MenuItem(status_menu, SWT.CASCADE);
        status_clip_item.setMenu(status_clip_menu);
        status_clip_item.setText(MessageText.getString("label.copy.to.clipboard"));
        MenuItem status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.key"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard(chat.getKey());
            }
        });
        status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.url"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard(chat.getURL());
            }
        });
        status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.rss.url"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard("azplug:?id=azbuddy&arg=" + UrlUtils.encode(chat.getURL() + "&format=rss"));
            }
        });
        status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.pk"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard(Base32.encode(chat.getPublicKey()));
            }
        });
        status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.export"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard(chat.export());
            }
        });
        if (!chat.isManaged()) {
            Menu status_channel_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
            MenuItem status_channel_item = new MenuItem(status_menu, SWT.CASCADE);
            status_channel_item.setMenu(status_channel_menu);
            status_channel_item.setText(MessageText.getString("azbuddy.dchat.rchans"));
            // Managed channel
            status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
            status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.managed"));
            status_mi.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    try {
                        ChatInstance inst = chat.getManagedChannel();
                        BuddyPluginViewBetaChat.createChatWindow(view, plugin, inst);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
            // RO channel
            status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
            status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.ro"));
            status_mi.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    try {
                        ChatInstance inst = chat.getReadOnlyChannel();
                        createChatWindow(view, plugin, inst);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
            // Random sub-channel
            status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
            status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.rand"));
            status_mi.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    try {
                        byte[] rand = new byte[20];
                        RandomUtils.nextSecureBytes(rand);
                        ChatInstance inst = beta.getChat(chat.getNetwork(), chat.getKey() + " {" + Base32.encode(rand) + "}");
                        createChatWindow(view, plugin, inst);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
            if (beta.isI2PAvailable()) {
                status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
                status_mi.setText(MessageText.getString(chat.getNetwork() == AENetworkClassifier.AT_I2P ? "azbuddy.dchat.rchans.pub" : "azbuddy.dchat.rchans.anon"));
                status_mi.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        try {
                            ChatInstance inst = beta.getChat(chat.getNetwork() == AENetworkClassifier.AT_I2P ? AENetworkClassifier.AT_PUBLIC : AENetworkClassifier.AT_I2P, chat.getKey());
                            createChatWindow(view, plugin, inst);
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                });
            }
        }
        final MenuItem fave_mi = new MenuItem(status_menu, SWT.CHECK);
        fave_mi.setText(MessageText.getString("label.fave"));
        fave_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setFavourite(fave_mi.getSelection());
            }
        });
        final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
        sis_mi.setText(MessageText.getString(Utils.isAZ2UI() ? "label.show.in.tab" : "label.show.in.sidebar"));
        sis_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
            }
        });
        addFriendsMenu(status_menu);
        // advanced
        final Menu advanced_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
        MenuItem advanced_menu_item = new MenuItem(status_menu, SWT.CASCADE);
        advanced_menu_item.setMenu(advanced_menu);
        advanced_menu_item.setText(MessageText.getString("MyTorrentsView.menu.advancedmenu"));
        // rename
        final MenuItem rename_mi = new MenuItem(advanced_menu, SWT.PUSH);
        rename_mi.setText(MessageText.getString("MyTorrentsView.menu.rename"));
        rename_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                String name = chat.getDisplayName();
                if (name == null) {
                    name = chat.getName();
                }
                UISWTInputReceiver entry = new SimpleTextEntryWindow();
                entry.setPreenteredText(name, false);
                entry.maintainWhitespace(false);
                entry.allowEmptyInput(false);
                entry.setLocalisedTitle(MessageText.getString("label.rename", new String[] { name }));
                entry.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entry) {
                        if (!entry.hasSubmittedInput()) {
                            return;
                        }
                        String input = entry.getSubmittedInput().trim();
                        if (input.length() > 0) {
                            try {
                                chat.setDisplayName(input);
                            } catch (Throwable e) {
                                Debug.printStackTrace(e);
                            }
                        }
                    }
                });
            }
        });
        // view type
        final Menu vt_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
        MenuItem vt_menu_item = new MenuItem(advanced_menu, SWT.CASCADE);
        vt_menu_item.setMenu(vt_menu);
        vt_menu_item.setText(MessageText.getString("menu.view.options"));
        SelectionAdapter listener = new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int vt = -1;
                for (MenuItem mi : vt_menu.getItems()) {
                    if (mi.getSelection()) {
                        vt = (Integer) mi.getData();
                    }
                }
                if (vt != -1) {
                    chat.setViewType(vt);
                    buildSupport(main_component);
                    main_component.layout(true, true);
                }
            }
        };
        MenuItem vt_mi = new MenuItem(vt_menu, SWT.RADIO);
        vt_mi.setText(MessageText.getString("label.full"));
        vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_DEFAULT);
        vt_mi.addSelectionListener(listener);
        vt_mi = new MenuItem(vt_menu, SWT.RADIO);
        vt_mi.setText(MessageText.getString("ConfigView.section.sharing"));
        vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_SHARING);
        if (chat.isReadOnly()) {
            vt_mi.setEnabled(false);
        }
        vt_mi.addSelectionListener(listener);
        vt_menu.addMenuListener(new MenuAdapter() {

            @Override
            public void menuShown(MenuEvent e) {
                int vt = chat.getViewType();
                for (MenuItem mi : vt_menu.getItems()) {
                    mi.setSelection(vt == (Integer) mi.getData());
                }
            }
        });
        // persist messages
        final MenuItem persist_mi = new MenuItem(advanced_menu, SWT.CHECK);
        persist_mi.setText(MessageText.getString("azbuddy.dchat.save.messages"));
        persist_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setSaveMessages(persist_mi.getSelection());
            }
        });
        final MenuItem log_mi = new MenuItem(advanced_menu, SWT.CHECK);
        log_mi.setText(MessageText.getString("azbuddy.dchat.log.messages"));
        log_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setLogMessages(log_mi.getSelection());
            }
        });
        final MenuItem automute_mi = new MenuItem(advanced_menu, SWT.CHECK);
        automute_mi.setText(MessageText.getString("azbuddy.dchat.auto.mute"));
        automute_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setAutoMute(automute_mi.getSelection());
            }
        });
        final MenuItem postnotifications_mi = new MenuItem(advanced_menu, SWT.CHECK);
        postnotifications_mi.setText(MessageText.getString("azbuddy.dchat.post.to.notifcations"));
        postnotifications_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setEnableNotificationsPost(postnotifications_mi.getSelection());
            }
        });
        final MenuItem disableindicators_mi = new MenuItem(advanced_menu, SWT.CHECK);
        disableindicators_mi.setText(MessageText.getString("azbuddy.dchat.disable.msg.indicators"));
        disableindicators_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setDisableNewMsgIndications(disableindicators_mi.getSelection());
            }
        });
        // setup menu
        status_menu.addMenuListener(new MenuAdapter() {

            @Override
            public void menuShown(MenuEvent e) {
                fave_mi.setSelection(chat.isFavourite());
                persist_mi.setSelection(chat.getSaveMessages());
                log_mi.setSelection(chat.getLogMessages());
                automute_mi.setSelection(chat.getAutoMute());
                postnotifications_mi.setSelection(chat.getEnableNotificationsPost());
                boolean disable_indications = chat.getDisableNewMsgIndications();
                disableindicators_mi.setSelection(disable_indications);
                postnotifications_mi.setEnabled(!disable_indications);
            }
        });
    } else {
        final Menu status_priv_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
        MenuItem status_priv_item = new MenuItem(status_menu, SWT.CASCADE);
        status_priv_item.setMenu(status_priv_menu);
        status_priv_item.setText(MessageText.getString("label.private.chat"));
        SelectionAdapter listener = new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                beta.setPrivateChatState((Integer) ((MenuItem) e.widget).getData());
            }
        };
        MenuItem status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
        status_mi.setText(MessageText.getString("label.enabled"));
        status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_ENABLED);
        status_mi.addSelectionListener(listener);
        status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
        status_mi.setText(MessageText.getString("label.pinned.only"));
        status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_PINNED_ONLY);
        status_mi.addSelectionListener(listener);
        status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
        status_mi.setText(MessageText.getString("label.disabled"));
        status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
        status_mi.addSelectionListener(listener);
        status_priv_menu.addMenuListener(new MenuAdapter() {

            @Override
            public void menuShown(MenuEvent e) {
                int pc_state = beta.getPrivateChatState();
                for (MenuItem mi : status_priv_menu.getItems()) {
                    mi.setSelection(pc_state == (Integer) mi.getData());
                }
            }
        });
        addFriendsMenu(status_menu);
        final MenuItem keep_alive_mi = new MenuItem(status_menu, SWT.CHECK);
        keep_alive_mi.setText(MessageText.getString("label.keep.alive"));
        status_menu.addMenuListener(new MenuAdapter() {

            @Override
            public void menuShown(MenuEvent e) {
                keep_alive_mi.setSelection(chat.getUserData("AC:KeepAlive") != null);
            }
        });
        keep_alive_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ChatInstance clone = (ChatInstance) chat.getUserData("AC:KeepAlive");
                if (clone != null) {
                    clone.destroy();
                    clone = null;
                } else {
                    try {
                        clone = chat.getClone();
                    } catch (Throwable f) {
                    }
                }
                chat.setUserData("AC:KeepAlive", clone);
            }
        });
        final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
        sis_mi.setText(MessageText.getString("label.show.in.sidebar"));
        sis_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) Label(org.eclipse.swt.widgets.Label) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Image(org.eclipse.swt.graphics.Image) Font(org.eclipse.swt.graphics.Font) Control(org.eclipse.swt.widgets.Control) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent) UISWTInputReceiver(com.biglybt.ui.swt.pif.UISWTInputReceiver) MouseEvent(org.eclipse.swt.events.MouseEvent) FontData(org.eclipse.swt.graphics.FontData) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) GridData(org.eclipse.swt.layout.GridData) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) DropTarget(org.eclipse.swt.dnd.DropTarget) Display(org.eclipse.swt.widgets.Display)

Example 34 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project epp.mpc by eclipse.

the class MarketplaceDropAdapter method hookRecursive.

private void hookRecursive(Control child, DropTargetListener dropListener) {
    DropTarget childTarget = findDropTarget(child);
    if (childTarget != null) {
        registerWithExistingTarget(childTarget);
        registerDropListener(childTarget, dropListener);
    }
    if (child instanceof Composite) {
        Composite composite = (Composite) child;
        Control[] children = composite.getChildren();
        for (Control control : children) {
            hookRecursive(control, dropListener);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 35 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project epp.mpc by eclipse.

the class MarketplaceDropAdapter method hookUrlTransfer.

private DropTarget hookUrlTransfer(final Shell shell, DropTargetAdapter dropListener) {
    DropTarget target = findDropTarget(shell);
    if (target != null) {
        // target exists, get it and check proper registration
        registerWithExistingTarget(target);
    } else {
        target = new DropTarget(shell, DROP_OPERATIONS);
        if (transferAgents == null) {
            transferAgents = new Transfer[] { URLTransfer.getInstance() };
        }
        target.setTransfer(transferAgents);
    }
    registerDropListener(target, dropListener);
    Control[] children = shell.getChildren();
    for (Control child : children) {
        hookRecursive(child, dropListener);
    }
    return target;
}
Also used : Control(org.eclipse.swt.widgets.Control) DropTarget(org.eclipse.swt.dnd.DropTarget)

Aggregations

DropTarget (org.eclipse.swt.dnd.DropTarget)85 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)46 DropTargetAdapter (org.eclipse.swt.dnd.DropTargetAdapter)27 DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)24 Transfer (org.eclipse.swt.dnd.Transfer)21 GridData (org.eclipse.swt.layout.GridData)17 Composite (org.eclipse.swt.widgets.Composite)17 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 Point (org.eclipse.swt.graphics.Point)15 GridLayout (org.eclipse.swt.layout.GridLayout)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 Button (org.eclipse.swt.widgets.Button)13 Label (org.eclipse.swt.widgets.Label)13 DragSource (org.eclipse.swt.dnd.DragSource)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 TextTransfer (org.eclipse.swt.dnd.TextTransfer)10 Control (org.eclipse.swt.widgets.Control)10 TreeItem (org.eclipse.swt.widgets.TreeItem)10 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)9