chqu1012 / RichClientFX

A lightweight EMF Rich Client Platform based on JavaFX
Apache License 2.0
2 stars 0 forks source link

CreateIdeFileDialog replaced the ListView with the following composite #504

Closed chqu1012 closed 5 years ago

chqu1012 commented 5 years ago
    Composite composite_1 = new Composite(container, SWT.NONE);
    composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    composite_1.setLayout(new GridLayout(3, false));

    Label lblAvailableAttributes = new Label(composite_1, SWT.NONE);
    lblAvailableAttributes.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    lblAvailableAttributes.setText("Available Attributes");
    new Label(composite_1, SWT.NONE);

    Label lblUsedAttributesFor = new Label(composite_1, SWT.NONE);
    lblUsedAttributesFor.setText("Used Attributes for Editing");

    editableAttributesListViewer = new ListViewer(composite_1, SWT.BORDER | SWT.V_SCROLL);
    List editableAttributesListView = editableAttributesListViewer.getList();
    GridData gd_editableAttributesListView = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    gd_editableAttributesListView.widthHint = 250;
    editableAttributesListView.setLayoutData(gd_editableAttributesListView);
    editableAttributesListViewer.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            if (element instanceof IMethod) {
                IMethod method = (IMethod) element;
                return method.getElementName();
            }
            return String.valueOf(element);
        };
    });
    editableAttributesListViewer.setContentProvider(ArrayContentProvider.getInstance());
    editableAttributesListViewer.setInput(availableAttributes);

    Composite composite = new Composite(composite_1, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    Button addButton = new Button(composite, SWT.NONE);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = editableAttributesListViewer.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) selection;
                usedAttributes.add((IMethod) ss.getFirstElement());
                availableAttributes.remove(ss.getFirstElement());
                editableAttributesListViewer.refresh();
                usedAttributeListViewer.refresh();
            }
        }
    });
    addButton.setBounds(0, 0, 75, 25);
    addButton.setText("->");

    Button removeButton = new Button(composite, SWT.NONE);
    removeButton.setText("<-");
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = editableAttributesListViewer.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) selection;
                availableAttributes.add((IMethod) ss.getFirstElement());
                usedAttributes.remove(ss.getFirstElement());
                editableAttributesListViewer.refresh();
                usedAttributeListViewer.refresh();
            }
        }
    });

    usedAttributeListViewer = new ListViewer(composite_1, SWT.BORDER | SWT.V_SCROLL);
    List usedAttributeListView = usedAttributeListViewer.getList();
    GridData gd_usedAttributeListView = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    gd_usedAttributeListView.widthHint = 250;
    usedAttributeListView.setLayoutData(gd_usedAttributeListView);
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);
    usedAttributeListViewer.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            if (element instanceof IMethod) {
                IMethod method = (IMethod) element;
                return method.getElementName();
            }
            return String.valueOf(element);
        };
    });
    usedAttributeListViewer.setContentProvider(ArrayContentProvider.getInstance());
    usedAttributeListViewer.setInput(usedAttributes);