Search in sources :

Example 66 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project polymap4-core by Polymap4.

the class UIUtils method addDropSupport.

/**
 * @param sourceControl The source of the drag event.
 * @param transfer The type of the transfer.
 * @return The newly created target.
 */
public static DropTarget addDropSupport(Control sourceControl, Transfer transfer, DropTargetAdapter listener) {
    int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT;
    DropTarget target = new DropTarget(sourceControl, operations);
    target.setTransfer(new Transfer[] { transfer });
    target.addDropListener(listener);
    return target;
}
Also used : DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 67 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project janrufmonitor by tbrandt77.

the class GosPage method createControl.

public void createControl(Composite c) {
    Composite co = new Composite(c, SWT.NONE);
    co.setLayout(new GridLayout(2, false));
    co.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    int operations = DND.DROP_MOVE;
    Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
    DropTarget target = new DropTarget(co, operations);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {

        public void drop(DropTargetEvent event) {
            // A drop has occurred, copy over the data
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            File f = new File(((String[]) event.data)[0]);
            m_logger.info("Detected drag action with file: " + f.getAbsolutePath());
            if (f.exists() && f.getName().toLowerCase().endsWith(".jam.zip")) {
                ZipArchive zip = new ZipArchive(f, false);
                try {
                    zip.open();
                    List files = zip.list(new FilenameFilter() {

                        public boolean accept(File f, String name) {
                            return name.toLowerCase().startsWith("install/repository.") && name.toLowerCase().endsWith(".inf");
                        }
                    });
                    if (files.size() == 1) {
                        m_logger.info("Found a valid generic online module.");
                        Properties inf = new Properties();
                        inf.load(zip.get((String) files.get(0)));
                        String ns = ((String) files.get(0)).substring("install/repository.".length(), ((String) files.get(0)).length() - 4);
                        name.setText(ns);
                        url.setText(inf.getProperty("repository." + ns + ":url:value", ""));
                        offset.setText(inf.getProperty("repository." + ns + ":skipbytes:value", "0"));
                        lastname.setText(inf.getProperty("repository." + ns + ":regexp.lastname:value", ""));
                        firstname.setText(inf.getProperty("repository." + ns + ":regexp.firstname:value", ""));
                        street.setText(inf.getProperty("repository." + ns + ":regexp.street:value", ""));
                        streetno.setText(inf.getProperty("repository." + ns + ":regexp.streetno:value", ""));
                        postal.setText(inf.getProperty("repository." + ns + ":regexp.pcode:value", ""));
                        city.setText(inf.getProperty("repository." + ns + ":regexp.city:value", ""));
                        area.setText(inf.getProperty("repository." + ns + ":regexp.areacode:value", ""));
                        number.setText(inf.getProperty("repository." + ns + ":regexp.phone:value", ""));
                        intarea.setText(inf.getProperty("repository." + ns + ":intareacode:value", ""));
                    }
                    zip.close();
                } catch (ZipArchiveException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                } catch (IOException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    });
    Label l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "name", "label", this.m_language));
    GridData gd = new GridData();
    gd.widthHint = 150;
    name = new Text(co, SWT.BORDER);
    name.setLayoutData(gd);
    name.setText("");
    name.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "version", "label", this.m_language));
    gd = new GridData();
    gd.widthHint = 50;
    version = new Text(co, SWT.BORDER);
    version.setLayoutData(gd);
    version.setText("1.0.0");
    version.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "url", "label", this.m_language));
    url = new Text(co, SWT.BORDER);
    gd.widthHint = 300;
    url.setLayoutData(gd);
    url.setText("");
    url.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "offset", "label", this.m_language));
    offset = new Text(co, SWT.BORDER);
    offset.setText("");
    offset.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "lastname", "label", this.m_language));
    lastname = new Text(co, SWT.BORDER);
    lastname.setLayoutData(gd);
    lastname.setText("");
    lastname.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            lastname.setForeground(new Color(lastname.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "firstname", "label", this.m_language));
    firstname = new Text(co, SWT.BORDER);
    firstname.setText("");
    firstname.setLayoutData(gd);
    firstname.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            firstname.setForeground(new Color(firstname.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "street", "label", this.m_language));
    street = new Text(co, SWT.BORDER);
    street.setLayoutData(gd);
    street.setText("");
    street.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            street.setForeground(new Color(street.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "streetno", "label", this.m_language));
    streetno = new Text(co, SWT.BORDER);
    streetno.setLayoutData(gd);
    streetno.setText("");
    streetno.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            streetno.setForeground(new Color(streetno.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "postal", "label", this.m_language));
    postal = new Text(co, SWT.BORDER);
    postal.setLayoutData(gd);
    postal.setText("");
    postal.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            postal.setForeground(new Color(postal.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "city", "label", this.m_language));
    city = new Text(co, SWT.BORDER);
    city.setLayoutData(gd);
    city.setText("");
    city.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            city.setForeground(new Color(city.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "area", "label", this.m_language));
    area = new Text(co, SWT.BORDER);
    area.setLayoutData(gd);
    area.setText("");
    area.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            area.setForeground(new Color(area.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "number", "label", this.m_language));
    number = new Text(co, SWT.BORDER);
    number.setLayoutData(gd);
    number.setText("");
    number.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            number.setForeground(new Color(number.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "intarea", "label", this.m_language));
    intarea = new Text(co, SWT.BORDER);
    intarea.setText("49");
    intarea.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "locale", "label", this.m_language));
    Locale[] locales = Locale.getAvailableLocales();
    List localeList = new ArrayList(locales.length);
    Locale lo = null;
    for (int i = 0; i < locales.length; i++) {
        lo = locales[i];
        if (lo.toString().indexOf("_") > 0)
            localeList.add(lo);
    }
    Collections.sort(localeList, new Comparator() {

        public int compare(Object l1, Object l2) {
            if (l1 instanceof Locale && l2 instanceof Locale) {
                return ((Locale) l1).getDisplayCountry().compareTo(((Locale) l2).getDisplayCountry());
            }
            return 0;
        }
    });
    String[] countryNames = new String[localeList.size()];
    for (int i = 0; i < localeList.size(); i++) {
        countryNames[i] = ((Locale) localeList.get(i)).getDisplayCountry() + " (" + ((Locale) localeList.get(i)).getDisplayLanguage() + ")";
    }
    locale = new Combo(co, SWT.READ_ONLY);
    locale.setItems(countryNames);
    for (int i = 0; i < countryNames.length; i++) {
        locale.setData(countryNames[i], localeList.get(i));
    }
    locale.select(0);
    locale.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "encoding", "label", this.m_language));
    String[] encodings = new String[] { "ISO-8859-1", "UTF-8", "UTF-16" };
    encoding = new Combo(co, SWT.READ_ONLY);
    encoding.setItems(encodings);
    for (int i = 0; i < encodings.length; i++) {
        encoding.setData(encodings[i], encodings[i]);
    }
    encoding.select(0);
    locale.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    Composite dco2 = new Composite(co, SWT.NONE);
    dco2.setLayout(new GridLayout(1, false));
    gd = new GridData();
    gd.horizontalSpan = 2;
    dco2.setLayoutData(gd);
    ffe = new FileFieldEditor(this.m_i18n.getString(this.getNamespace(), "fname", "label", this.m_language), this.m_i18n.getString(this.getNamespace(), "flabel", "label", this.m_language), dco2);
    ffe.setFileExtensions(new String[] { "*.png" });
    l = new Label(co, SWT.LEFT);
    l = new Label(co, SWT.LEFT);
    Composite dco = new Composite(co, SWT.NONE);
    dco.setLayout(new GridLayout(1, false));
    gd = new GridData();
    gd.horizontalSpan = 2;
    dco.setLayoutData(gd);
    dfe = new DirectoryFieldEditor(this.m_i18n.getString(this.getNamespace(), "dname", "label", this.m_language), this.m_i18n.getString(this.getNamespace(), "dlabel", "label", this.m_language), this.m_i18n.getString(this.getNamespace(), "dmessage", "label", this.m_language), dco);
    dfe.setStringValue(PathResolver.getInstance().getTempDirectory());
    Group c2 = new Group(co, SWT.SHADOW_ETCHED_IN);
    c2.setLayout(new GridLayout(2, false));
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = GridData.FILL_HORIZONTAL;
    c2.setLayoutData(gd);
    l = new Label(c2, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "testnumber", "label", this.m_language));
    l = new Label(c2, SWT.LEFT);
    final Text testnum = new Text(c2, SWT.BORDER);
    testnum.setText("");
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    // gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
    testnum.setLayoutData(gd);
    final Button test = new Button(c2, SWT.PUSH);
    test.setEnabled(false);
    test.setText(this.m_i18n.getString(this.getNamespace(), "test", "label", this.m_language));
    test.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(testnum.getText().startsWith("0") ? testnum.getText().substring(1) : testnum.getText());
            pn.setIntAreaCode(intarea.getText());
            Properties config = new Properties();
            config.setProperty("version", version.getText());
            config.setProperty("skipbytes", offset.getText());
            config.setProperty("url", url.getText());
            config.setProperty("regexp.lastname", lastname.getText());
            config.setProperty("regexp.firstname", firstname.getText());
            config.setProperty("regexp.street", street.getText());
            config.setProperty("regexp.streetno", streetno.getText());
            config.setProperty("regexp.pcode", postal.getText());
            config.setProperty("regexp.city", city.getText());
            config.setProperty("regexp.areacode", area.getText());
            config.setProperty("regexp.phone", number.getText());
            config.setProperty("intareacode", intarea.getText());
            config.setProperty("locale", ((Locale) locale.getData(locale.getText())).toString());
            config.setProperty("encoding", encoding.getText());
            config.setProperty("icon", ffe.getStringValue());
            TestWebCallerManager twcm = new TestWebCallerManager(config);
            try {
                ICaller c = twcm.getCaller(pn);
                IService dialog = getRuntime().getServiceFactory().getService("DefaultCallDialogService");
                if (dialog != null) {
                    ICall call = getRuntime().getCallFactory().createCall(c, getRuntime().getMsnManager().createMsn("12345"), getRuntime().getCipManager().createCip("1"));
                    if (dialog instanceof AbstractReceiverConfigurableService) {
                        ((AbstractReceiverConfigurableService) dialog).receivedValidRule(call);
                    }
                    lastname.setForeground(new Color(lastname.getDisplay(), 0, 0, 0));
                    firstname.setForeground(new Color(firstname.getDisplay(), 0, 0, 0));
                    street.setForeground(new Color(street.getDisplay(), 0, 0, 0));
                    streetno.setForeground(new Color(streetno.getDisplay(), 0, 0, 0));
                    postal.setForeground(new Color(postal.getDisplay(), 0, 0, 0));
                    city.setForeground(new Color(city.getDisplay(), 0, 0, 0));
                    area.setForeground(new Color(area.getDisplay(), 0, 0, 0));
                    number.setForeground(new Color(number.getDisplay(), 0, 0, 0));
                }
            } catch (CallerNotFoundException ex) {
                PropagationFactory.getInstance().fire(new Message(Message.INFO, getNamespace(), "notidentified", new String[] { pn.getTelephoneNumber() }, ex));
                // first CallerNotFoundException
                Throwable cause = ex.getCause();
                if (cause != null && !(cause instanceof RegExpURLRequesterException)) {
                    cause = cause.getCause();
                }
                if (cause != null && cause instanceof RegExpURLRequesterException) {
                    List failure = ((RegExpURLRequesterException) cause).getFailures();
                    String c = null;
                    for (int i = 0; i < failure.size(); i++) {
                        c = (String) failure.get(i);
                        if (c.equalsIgnoreCase("regexp.lastname")) {
                            lastname.setForeground(new Color(lastname.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.firstname")) {
                            firstname.setForeground(new Color(firstname.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.street")) {
                            street.setForeground(new Color(street.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.streetno")) {
                            streetno.setForeground(new Color(streetno.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.pcode")) {
                            postal.setForeground(new Color(postal.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.city")) {
                            city.setForeground(new Color(city.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.areacode")) {
                            area.setForeground(new Color(area.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.phone")) {
                            number.setForeground(new Color(number.getDisplay(), 255, 0, 0));
                        }
                    }
                }
            } finally {
                twcm = null;
            }
        }
    });
    testnum.addKeyListener(new KeyListener() {

        public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
            if (testnum.getText().length() > 0 && url.getText().length() > 0 && number.getText().length() > 0)
                test.setEnabled(true);
            else
                test.setEnabled(false);
        }

        public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
        }
    });
    this.setPageComplete(isComplete());
    this.setControl(co);
}
Also used : ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) Locale(java.util.Locale) RegExpURLRequesterException(de.janrufmonitor.repository.web.RegExpURLRequesterException) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) ZipArchive(de.janrufmonitor.repository.zip.ZipArchive) Combo(org.eclipse.swt.widgets.Combo) Comparator(java.util.Comparator) FileFieldEditor(org.eclipse.jface.preference.FileFieldEditor) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) IService(de.janrufmonitor.service.IService) AbstractReceiverConfigurableService(de.janrufmonitor.service.AbstractReceiverConfigurableService) Color(org.eclipse.swt.graphics.Color) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) ICaller(de.janrufmonitor.framework.ICaller) Transfer(org.eclipse.swt.dnd.Transfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) DropTarget(org.eclipse.swt.dnd.DropTarget) File(java.io.File) IPhonenumber(de.janrufmonitor.framework.IPhonenumber) Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) Message(de.janrufmonitor.exception.Message) DirectoryFieldEditor(de.janrufmonitor.ui.jface.configuration.controls.DirectoryFieldEditor) Properties(java.util.Properties) FilenameFilter(java.io.FilenameFilter) GridLayout(org.eclipse.swt.layout.GridLayout) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) ICall(de.janrufmonitor.framework.ICall) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) GridData(org.eclipse.swt.layout.GridData) KeyListener(org.eclipse.swt.events.KeyListener)

Example 68 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project janrufmonitor by tbrandt77.

the class AbstractTreeTableApplication method createContents.

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    List actions = this.getMenuBuilder().getToolbarActions();
    if (this.isShowToolbar() && actions != null && actions.size() > 0 && this.getToolBarManager() != null) {
        ToolBar tb = this.getToolBarManager().createControl(composite);
        for (int i = 0, j = actions.size(); i < j; i++) {
            final org.eclipse.jface.action.IAction a = (org.eclipse.jface.action.IAction) actions.get(i);
            if (a != null && a.getImageDescriptor() != null) {
                ToolItem ti = new ToolItem(tb, SWT.PUSH);
                Image img = (a).getImageDescriptor().createImage();
                ti.setImage(img);
                ti.setText(a.getText());
                if (a instanceof AbstractAction) {
                    ti.setText(((AbstractAction) a).getShortText());
                }
                ti.setToolTipText(a.getToolTipText());
                ti.addSelectionListener(new SelectionAdapter() {

                    public void widgetSelected(SelectionEvent e) {
                        a.run();
                    }
                });
            }
        }
    }
    addRenderBeforeTableHooks(composite);
    // add filter capability
    Composite line = new Composite(composite, SWT.NONE);
    line.setLayout(new GridLayout(6, false));
    if (this.getFilterManager() != null) {
        Composite view = new Composite(line, SWT.NONE);
        view.setLayout(new GridLayout(2, false));
        new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "current_view", "label", this.getLanguage()));
        new Label(view, SWT.NONE);
        this.currentView = new Combo(view, SWT.READ_ONLY | SWT.FLAT);
        this.currentView.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                String filterName = currentView.getItem(currentView.getSelectionIndex());
                IFilter[] selectedFilters = (IFilter[]) currentView.getData(filterName);
                getApplication().getConfiguration().setProperty(CFG_FILTER, getFilterManager().getFiltersToString(selectedFilters));
                getApplication().storeConfiguration();
                updateViews(true);
            }
        });
        if (getFilterAction() != null) {
            Button filterAction = new Button(view, SWT.PUSH);
            filterAction.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    de.janrufmonitor.ui.jface.application.action.IAction action = getFilterAction();
                    if (action != null)
                        action.run();
                }
            });
            filterAction.setImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_FILTER_GIF));
            filterAction.pack();
        }
    }
    final de.janrufmonitor.ui.jface.application.action.IAction action = getQuickSearchAction();
    if (this.isShowQuickSearch() && action != null) {
        Composite view = new Composite(line, SWT.NONE);
        view.setLayout(new GridLayout(2, false));
        new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "label", this.getLanguage()));
        new Label(view, SWT.NONE);
        final Combo search = new Combo(view, SWT.FLAT);
        final String empty = this.getConfiguration().getProperty(CFG_SEARCHTERMS, "");
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.minimumWidth = 300;
        search.setLayoutData(gd);
        search.add(empty);
        final List sh = this.getSearchHistory();
        for (int i = 0; i < sh.size(); i++) {
            if (!empty.equalsIgnoreCase((String) sh.get(i)))
                search.add((String) sh.get(i));
        }
        search.select(0);
        search.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                action.setData(search.getText());
                action.run();
            }
        });
        search.setToolTipText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "description", this.getLanguage()));
        search.addKeyListener(new KeyAdapter() {

            public void keyPressed(KeyEvent e) {
                if (e.character == 13) {
                    action.setData(search.getText());
                    if (!sh.contains(search.getText())) {
                        sh.add(search.getText());
                        search.add(search.getText());
                    }
                    setSearchHistory(sh);
                    action.run();
                }
            }
        });
    }
    Tree t = new Tree(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
    viewer = new TreeViewer(t);
    Tree tree = ((TreeViewer) viewer).getTree();
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    tree.setHeaderVisible(true);
    tree.addTreeListener(new TreeAdapter() {

        public void treeExpanded(TreeEvent e) {
            if (e.item != null) {
                TreeItem item = (TreeItem) e.item;
                TreeItem[] items = item.getItems();
                for (int i = 0; i < items.length; i++) {
                    items[i].setBackground(item.getBackground());
                    items[i].setForeground(item.getForeground());
                }
            }
        }
    });
    this.updateProviders();
    // added drag and drop feature
    if (this.getDropTargetHandler() != null) {
        int operations = DND.DROP_MOVE;
        Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
        DropTarget target = new DropTarget(tree, operations);
        target.setTransfer(types);
        target.addDropListener(new DropTargetAdapter() {

            public void drop(DropTargetEvent event) {
                // A drop has occurred, copy over the data
                if (event.data == null) {
                    event.detail = DND.DROP_NONE;
                    return;
                }
                getDropTargetHandler().execute((String[]) event.data);
            }
        });
    }
    FontData tableFontData = tree.getFont().getFontData()[0];
    int size = Integer.parseInt(this.getConfiguration().getProperty(CFG_FONT_SIZE, "8"));
    tree.setFont(this.getSizedFont(tableFontData, size, false));
    AbstractMenuBuilder mb = this.getMenuBuilder();
    if (mb != null)
        tree.setMenu(mb.createPopupMenu(tree));
    tree.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.DEL) {
                de.janrufmonitor.ui.jface.application.action.IAction action = getDeleteAction();
                if (action != null)
                    action.run();
            }
        }
    });
    tree.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent e) {
            de.janrufmonitor.ui.jface.application.action.IAction action = getAssignAction();
            if (action != null)
                action.run();
        }
    });
    // 2006/08/02: this is a workaround: No multiple line in table possibe
    Listener paintListener = new Listener() {

        int name_column = getColumnNumber("name");

        int address_column = getColumnNumber("address");

        public void handleEvent(Event event) {
            if (event.index != name_column && event.index != address_column)
                return;
            switch(event.type) {
                case SWT.MeasureItem:
                    {
                        TreeItem item = (TreeItem) event.item;
                        String text = item.getText(event.index);
                        Point size = event.gc.textExtent(text);
                        event.width = size.x;
                        event.height = Math.max(event.height, size.y + 7);
                        break;
                    }
                case SWT.PaintItem:
                    {
                        TreeItem item = (TreeItem) event.item;
                        String text = item.getText(event.index);
                        Point size = event.gc.textExtent(text);
                        int offset2 = (event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0) + 3;
                        event.gc.drawText(text, event.x + offset2, event.y + offset2, true);
                        break;
                    }
                case SWT.EraseItem:
                    {
                        event.detail &= ~SWT.FOREGROUND;
                        TreeItem item = (TreeItem) event.item;
                        event.gc.setBackground(item.getBackground(event.index));
                        event.gc.setForeground(item.getForeground(event.index));
                        break;
                    }
            }
        }
    };
    tree.addListener(SWT.MeasureItem, paintListener);
    tree.addListener(SWT.PaintItem, paintListener);
    tree.addListener(SWT.EraseItem, paintListener);
    addRenderAfterTableHooks(composite);
    tree.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (e.widget instanceof Tree) {
                TreeItem[] selectedItems = ((Tree) e.widget).getSelection();
                if (selectedItems != null && selectedItems.length > 0)
                    lastMarkedTreeItem = ((Tree) e.widget).indexOf(selectedItems[0]);
                else
                    lastMarkedTreeItem = -1;
            }
        }
    });
    updateViews(true);
    List startupActions = this.getMenuBuilder().getStartupActions();
    if (startupActions != null && startupActions.size() > 0) {
        IAction a = null;
        for (int i = 0, j = startupActions.size(); i < j; i++) {
            a = (IAction) startupActions.get(i);
            if (a != null) {
                a.setApplication(this);
                a.run();
            }
        }
    }
    return composite;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) TreeAdapter(org.eclipse.swt.events.TreeAdapter) Image(org.eclipse.swt.graphics.Image) KeyEvent(org.eclipse.swt.events.KeyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) List(java.util.List) ArrayList(java.util.ArrayList) ToolItem(org.eclipse.swt.widgets.ToolItem) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) IAction(de.janrufmonitor.ui.jface.application.action.IAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FontData(org.eclipse.swt.graphics.FontData) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IAction(de.janrufmonitor.ui.jface.application.action.IAction) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) IFilter(de.janrufmonitor.repository.filter.IFilter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) Transfer(org.eclipse.swt.dnd.Transfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 69 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project janrufmonitor by tbrandt77.

the class AbstractTableApplication method createContents.

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    if (this.getMenuBuilder() != null) {
        List actions = this.getMenuBuilder().getToolbarActions();
        if (this.isShowToolbar() && actions != null && actions.size() > 0 && this.getToolBarManager() != null) {
            ToolBar tb = this.getToolBarManager().createControl(composite);
            for (int i = 0, j = actions.size(); i < j; i++) {
                final org.eclipse.jface.action.IAction a = (org.eclipse.jface.action.IAction) actions.get(i);
                if (a != null && a.getImageDescriptor() != null) {
                    ToolItem ti = new ToolItem(tb, SWT.PUSH);
                    Image img = (a).getImageDescriptor().createImage();
                    ti.setImage(img);
                    ti.setText(a.getText());
                    if (a instanceof AbstractAction) {
                        ti.setText(((AbstractAction) a).getShortText());
                    }
                    ti.setToolTipText(a.getToolTipText());
                    ti.addSelectionListener(new SelectionAdapter() {

                        public void widgetSelected(SelectionEvent e) {
                            a.run();
                        }
                    });
                }
            }
        }
    }
    addRenderBeforeTableHooks(composite);
    // add filter capability
    Composite line = new Composite(composite, SWT.NONE);
    line.setLayout(new GridLayout(6, false));
    if (this.getFilterManager() != null && this.getConfiguration().getProperty(CFG_ENABLE_FILTER_VIEW, "true").equalsIgnoreCase("true")) {
        Composite view = new Composite(line, SWT.NONE);
        view.setLayout(new GridLayout(2, false));
        new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "current_view", "label", this.getLanguage()));
        new Label(view, SWT.NONE);
        this.currentView = new Combo(view, SWT.READ_ONLY | SWT.FLAT);
        this.currentView.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                String filterName = currentView.getItem(currentView.getSelectionIndex());
                IFilter[] selectedFilters = (IFilter[]) currentView.getData(filterName);
                getApplication().getConfiguration().setProperty(CFG_FILTER, getFilterManager().getFiltersToString(selectedFilters));
                getApplication().storeConfiguration();
                updateViews(true);
            }
        });
        if (getFilterAction() != null) {
            Button filterAction = new Button(view, SWT.PUSH);
            filterAction.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    de.janrufmonitor.ui.jface.application.action.IAction action = getFilterAction();
                    if (action != null)
                        action.run();
                }
            });
            filterAction.setImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_FILTER_GIF));
            filterAction.pack();
        }
    }
    final de.janrufmonitor.ui.jface.application.action.IAction action = getQuickSearchAction();
    if (this.isShowQuickSearch() && action != null) {
        Composite view = new Composite(line, SWT.NONE);
        view.setLayout(new GridLayout(2, false));
        new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "label", this.getLanguage()));
        new Label(view, SWT.NONE);
        final Combo search = new Combo(view, SWT.FLAT);
        final String empty = this.getConfiguration().getProperty(CFG_SEARCHTERMS, "");
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.minimumWidth = 300;
        search.setLayoutData(gd);
        search.add(empty);
        final List sh = this.getSearchHistory();
        for (int i = 0; i < sh.size(); i++) {
            if (!empty.equalsIgnoreCase((String) sh.get(i)))
                search.add((String) sh.get(i));
        }
        search.select(0);
        search.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                action.setData(search.getText());
                action.run();
            }
        });
        search.setToolTipText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "description", this.getLanguage()));
        search.addKeyListener(new KeyAdapter() {

            public void keyPressed(KeyEvent e) {
                if (e.character == 13) {
                    action.setData(search.getText());
                    if (!sh.contains(search.getText())) {
                        sh.add(search.getText());
                        search.add(search.getText());
                    }
                    setSearchHistory(sh);
                    action.run();
                }
            }
        });
    }
    viewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.VIRTUAL);
    final Table table = ((TableViewer) viewer).getTable();
    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    table.setHeaderVisible(true);
    this.updateProviders();
    // added drag and drop feature
    if (this.getDropTargetHandler() != null) {
        int operations = DND.DROP_MOVE;
        Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
        DropTarget target = new DropTarget(table, operations);
        target.setTransfer(types);
        target.addDropListener(new DropTargetAdapter() {

            public void drop(DropTargetEvent event) {
                // A drop has occurred, copy over the data
                if (event.data == null) {
                    event.detail = DND.DROP_NONE;
                    return;
                }
                getDropTargetHandler().execute((String[]) event.data);
            }
        });
    }
    FontData tableFontData = table.getFont().getFontData()[0];
    int size = Integer.parseInt(this.getConfiguration().getProperty(CFG_FONT_SIZE, "8"));
    table.setFont(this.getSizedFont(tableFontData, size, false));
    AbstractMenuBuilder mb = this.getMenuBuilder();
    if (mb != null)
        table.setMenu(mb.createPopupMenu(table));
    table.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.DEL) {
                de.janrufmonitor.ui.jface.application.action.IAction action = getDeleteAction();
                if (action != null && action instanceof org.eclipse.jface.action.IAction && ((org.eclipse.jface.action.IAction) action).isEnabled())
                    action.run();
            }
        }
    });
    table.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent e) {
            de.janrufmonitor.ui.jface.application.action.IAction action = getAssignAction();
            if (action != null && action instanceof org.eclipse.jface.action.IAction && ((org.eclipse.jface.action.IAction) action).isEnabled())
                action.run();
        }
    });
    // 2006/08/02: this is a workaraound: No multiple line in table possibe
    Listener paintListener = new Listener() {

        int name_column = getColumnNumber("name");

        int address_column = getColumnNumber("address");

        int img_column = getColumnNumber("imagepreview");

        // removed 2010/02/17: do to usability notes column is not rendered with SWT.WRAP
        // int notes_column = getColumnNumber("notes");
        public void handleEvent(Event event) {
            if (event.index == img_column) {
                TableItem it = (TableItem) event.item;
                it.setText(event.index, IJAMConst.CRLF + IJAMConst.CRLF + IJAMConst.CRLF);
                switch(event.type) {
                    case SWT.MeasureItem:
                        {
                            TableItem item = (TableItem) event.item;
                            String text = item.getText(event.index);
                            Point size = event.gc.textExtent(text);
                            event.width = size.x;
                            event.height = Math.max(event.height, size.y + 7);
                            break;
                        }
                    case SWT.PaintItem:
                        {
                            TableItem item = (TableItem) event.item;
                            String text = item.getText(event.index);
                            Point size = event.gc.textExtent(text);
                            int offset2 = (event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0) + 3;
                            event.gc.drawText(text, event.x + offset2, event.y + offset2, true);
                            break;
                        }
                    case SWT.EraseItem:
                        {
                            event.detail &= ~SWT.FOREGROUND;
                            break;
                        }
                }
                return;
            }
            if (event.index != name_column && event.index != address_column)
                /**
                 *&& event.index!=notes_column
                 */
                return;
            switch(event.type) {
                case SWT.MeasureItem:
                    {
                        TableItem item = (TableItem) event.item;
                        String text = item.getText(event.index);
                        Point size = event.gc.textExtent(text);
                        event.width = size.x;
                        event.height = Math.max(event.height, size.y + 7);
                        break;
                    }
                case SWT.PaintItem:
                    {
                        TableItem item = (TableItem) event.item;
                        String text = item.getText(event.index);
                        Point size = event.gc.textExtent(text);
                        int offset2 = (event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0) + 3;
                        event.gc.drawText(text, event.x + offset2, event.y + offset2, true);
                        break;
                    }
                case SWT.EraseItem:
                    {
                        event.detail &= ~SWT.FOREGROUND;
                        break;
                    }
            }
        }
    };
    table.addListener(SWT.MeasureItem, paintListener);
    table.addListener(SWT.PaintItem, paintListener);
    table.addListener(SWT.EraseItem, paintListener);
    // table.addListener(SWT.SetData, new Listener() {
    // 
    // public void handleEvent(Event e) {
    // TableItem item = (TableItem)e.item;
    // int index = table.indexOf(item);
    // item.setText("Item "+index);
    // 
    // }
    // 
    // });
    addRenderAfterTableHooks(composite);
    table.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (e.widget instanceof Table) {
                lastMarkedRow = ((Table) e.widget).getSelectionIndex();
            }
        }
    });
    updateViews(true);
    if (this.getMenuBuilder() != null) {
        List startupActions = this.getMenuBuilder().getStartupActions();
        if (startupActions != null && startupActions.size() > 0) {
            IAction a = null;
            for (int i = 0, j = startupActions.size(); i < j; i++) {
                a = (IAction) startupActions.get(i);
                if (a != null) {
                    a.setApplication(this);
                    a.run();
                }
            }
        }
    }
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ArrayList(java.util.ArrayList) List(java.util.List) IAction(de.janrufmonitor.ui.jface.application.action.IAction) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IAction(de.janrufmonitor.ui.jface.application.action.IAction) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) IFilter(de.janrufmonitor.repository.filter.IFilter) GridData(org.eclipse.swt.layout.GridData) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Transfer(org.eclipse.swt.dnd.Transfer) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTarget(org.eclipse.swt.dnd.DropTarget) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 70 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project janrufmonitor by tbrandt77.

the class ModuleManager method createContents.

protected Control createContents(Composite parent) {
    this.setTitle(this.m_i18n.getString(this.getNamespace(), "title", "label", this.m_language));
    this.noDefaultAndApplyButton();
    Composite c = new Composite(parent, SWT.NONE);
    c.setLayout(new GridLayout(2, false));
    int operations = DND.DROP_MOVE;
    Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
    DropTarget target = new DropTarget(c, operations);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {

        public void drop(DropTargetEvent event) {
            // A drop has occurred, copy over the data
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            getDropTargetHandler().execute((String[]) event.data);
        }
    });
    GridData gd = new GridData();
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 1;
    gd.widthHint = 200;
    Label l = new Label(c, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "file", "label", this.m_language));
    l.pack();
    l = new Label(c, SWT.LEFT);
    final org.eclipse.swt.widgets.List m_fileList = new org.eclipse.swt.widgets.List(c, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    m_fileList.setLayoutData(gd);
    Button b = new Button(c, SWT.PUSH);
    b.setText(JFaceResources.getString("openBrowse"));
    final Button install = new Button(c, SWT.PUSH);
    install.setText(this.m_i18n.getString(this.getNamespace(), "install", "label", this.m_language));
    install.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            ModuleContainer mc = (ModuleContainer) m_fileList.getData("modules");
            if (mc != null) {
                String[] sources = new String[mc.getFilenames().length];
                for (int i = 0, j = mc.getFilenames().length; i < j; i++) {
                    sources[i] = mc.getDirectory() + File.separator + mc.getFilenames()[i];
                }
                getDropTargetHandler().execute(sources);
            }
            install.setEnabled(false);
            m_fileList.removeAll();
            m_fileList.setData("modules", null);
        }
    });
    install.setEnabled(false);
    b.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent evt) {
            ModuleContainer mc = changePressed(m_fileList.getParent());
            if (mc != null) {
                m_fileList.removeAll();
                m_fileList.setData("modules", null);
                m_fileList.setData("modules", mc);
                String[] mods = mc.getFilenames();
                for (int i = 0; i < mods.length; i++) m_fileList.add(mods[i]);
                if (mods.length > 0) {
                    install.setEnabled(true);
                }
            }
        }
    });
    l = new Label(c, SWT.LEFT);
    l = new Label(c, SWT.LEFT);
    l = new Label(c, SWT.LEFT);
    l = new Label(c, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "remove", "label", this.m_language));
    l = new Label(c, SWT.LEFT);
    final Combo module = new Combo(c, SWT.READ_ONLY);
    gd = new GridData();
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 1;
    gd.widthHint = 200;
    module.setLayoutData(gd);
    this.buildCombobox(module);
    l = new Label(c, SWT.LEFT);
    if (module.getItemCount() > 0 && !OSUtils.isMultiuserEnabled()) {
        final Group info = new Group(c, SWT.SHADOW_ETCHED_IN);
        info.setLayout(new GridLayout(2, false));
        gd = new GridData();
        gd.horizontalAlignment = GridData.FILL;
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalSpan = 2;
        info.setLayoutData(gd);
        info.setText(this.m_i18n.getString(this.getNamespace(), "infotitle", "label", this.m_language));
        info.setVisible(false);
        l = new Label(info, SWT.LEFT);
        l.setText(this.m_i18n.getString(this.getNamespace(), "modname", "label", this.m_language));
        final Label name = new Label(info, SWT.LEFT);
        l = new Label(info, SWT.LEFT);
        l.setText(this.m_i18n.getString(this.getNamespace(), "modversion", "label", this.m_language));
        final Label version = new Label(info, SWT.LEFT);
        l = new Label(info, SWT.LEFT);
        l.setText(this.m_i18n.getString(this.getNamespace(), "modtype", "label", this.m_language));
        final Label type = new Label(info, SWT.LEFT);
        l = new Label(info, SWT.LEFT);
        l.setText(this.m_i18n.getString(this.getNamespace(), "modauthor", "label", this.m_language));
        final Label author = new Label(info, SWT.LEFT);
        l = new Label(info, SWT.LEFT);
        l.setText(this.m_i18n.getString(this.getNamespace(), "modwebsite", "label", this.m_language));
        final HyperLink website = new HyperLink(info, SWT.NONE);
        website.setEnabled(false);
        website.addMouseListener(new MouseAdapter() {

            public void mouseDown(MouseEvent e) {
                if (e.button == 1)
                    Program.launch(website.getText());
            }
        });
        String ns = (String) module.getData(module.getText());
        if (ns != null && ns.length() > 0) {
            info.setVisible(true);
            Properties currentDescriptor = InstallerEngine.getInstance().getDescriptor(ns);
            if (currentDescriptor != null) {
                name.setText(this.getNamespaceLabel(ns));
                version.setText(currentDescriptor.getProperty(InstallerConst.DESCRIPTOR_VERSION, "-"));
                author.setText(currentDescriptor.getProperty(InstallerConst.DESCRIPTOR_AUTHOR, "-"));
                type.setText(m_i18n.getString(getNamespace(), currentDescriptor.getProperty(InstallerConst.DESCRIPTOR_TYPE, "-"), "label", m_language));
                website.setText(currentDescriptor.getProperty(InstallerConst.DESCRIPTOR_WEBSITE, "-"));
                if (website.getText().length() > 6 && website.getText().toLowerCase().startsWith("http")) {
                    website.setEnabled(true);
                }
            }
        }
        module.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                String ns = (String) module.getData(module.getText());
                if (ns != null && ns.length() > 0) {
                    info.setVisible(true);
                    Properties currentDescriptor = InstallerEngine.getInstance().getDescriptor(ns);
                    if (currentDescriptor != null) {
                        name.setText(getNamespaceLabel(ns));
                        name.pack();
                        version.setText(currentDescriptor.getProperty(InstallerConst.DESCRIPTOR_VERSION, "-"));
                        version.pack();
                        author.setText(currentDescriptor.getProperty(InstallerConst.DESCRIPTOR_AUTHOR, "-"));
                        author.pack();
                        type.setText(m_i18n.getString(getNamespace(), currentDescriptor.getProperty(InstallerConst.DESCRIPTOR_TYPE, "-"), "label", m_language));
                        type.pack();
                        website.setText(currentDescriptor.getProperty(InstallerConst.DESCRIPTOR_WEBSITE, "-"));
                        if (website.getText().length() > 6 && website.getText().toLowerCase().startsWith("http")) {
                            website.setEnabled(true);
                        }
                        website.pack();
                    }
                }
            }
        });
    }
    final Button uninstall = new Button(c, SWT.PUSH | SWT.LEFT);
    uninstall.setText(this.m_i18n.getString(this.getNamespace(), "uninstall", "label", this.m_language));
    if (module.getItemCount() == 0 || OSUtils.isMultiuserEnabled()) {
        uninstall.setEnabled(false);
    }
    uninstall.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            String ns = (String) module.getData(module.getText());
            MessageBox messageBox = new MessageBox(uninstall.getShell(), SWT.APPLICATION_MODAL | SWT.YES | SWT.NO);
            messageBox.setMessage(m_i18n.getString(getNamespace(), "confirmdelete", "label", m_language));
            if (messageBox.open() == SWT.YES) {
                if (InstallerEngine.getInstance().uninstall(ns)) {
                    m_logger.info("Removed <" + ns + "> module successfully.");
                    if (module.getItemCount() == 0) {
                        uninstall.setEnabled(false);
                    }
                    MessageDialog.openInformation(install.getShell(), m_i18n.getString(getNamespace(), "okrtitle", "label", m_language), m_i18n.getString(getNamespace(), "okrmessage", "label", m_language));
                } else {
                    MessageDialog.openError(install.getShell(), m_i18n.getString(getNamespace(), "failrtitle", "label", m_language), m_i18n.getString(getNamespace(), "failrmessage", "label", m_language));
                }
                buildCombobox(module);
            }
        }
    });
    l = new Label(c, SWT.LEFT);
    return c;
}
Also used : Group(org.eclipse.swt.widgets.Group) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Properties(java.util.Properties) HyperLink(de.janrufmonitor.ui.jface.application.controls.HyperLink) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) MessageBox(org.eclipse.swt.widgets.MessageBox) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Transfer(org.eclipse.swt.dnd.Transfer) GridData(org.eclipse.swt.layout.GridData) 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