Search in sources :

Example 11 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project erlide_eclipse by erlang.

the class RuntimePreferencePage method createMyControl.

private Control createMyControl(final Composite ancestor) {
    final Composite parent = new Composite(ancestor, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);
    final Font font = ancestor.getFont();
    parent.setFont(font);
    GridData data;
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    composite.setLayout(gridLayout);
    final Label erlideLabel = new Label(composite, SWT.NONE);
    erlideLabel.setToolTipText("The erlide runtime is used for IDE purposes, not for running project code. " + "It is the most recent stable version that is installed.");
    final String erlideName = erlideRuntime == null ? "none" : erlideRuntime.getName();
    erlideLabel.setText(RuntimePreferenceMessages.RuntimePreferencePage_erlideLabel_text + " " + erlideName);
    new Label(composite, SWT.NONE);
    new Label(parent, SWT.NONE);
    final Label tableLabel = new Label(parent, SWT.NONE);
    tableLabel.setText("Installed runtimes:");
    data = new GridData();
    data.horizontalSpan = 2;
    tableLabel.setLayoutData(data);
    tableLabel.setFont(font);
    final Table table = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    table.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (e.detail == SWT.CHECK) {
                final RuntimeInfo ri = (RuntimeInfo) e.item.getData();
                defaultRuntime = ri;
            }
        }
    });
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.widthHint = 403;
    table.setLayoutData(data);
    table.setFont(font);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    final TableColumn column1 = new TableColumn(table, SWT.NULL);
    column1.setWidth(80);
    column1.setText(RuntimePreferenceMessages.name);
    column1.setResizable(true);
    column1.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            sortByName();
        }
    });
    final TableColumn column2 = new TableColumn(table, SWT.NULL);
    column2.setWidth(150);
    column2.setText("Directory");
    column2.setResizable(true);
    column2.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            sortByDirectory();
        }
    });
    final TableColumn column3 = new TableColumn(table, SWT.NULL);
    column3.setWidth(80);
    column3.setText("Version");
    column3.setResizable(false);
    fRuntimeList = new CheckboxTableViewer(table);
    fRuntimeList.setLabelProvider(new RuntimeLabelProvider());
    fRuntimeList.setContentProvider(new RuntimeContentProvider());
    fRuntimeList.setInput(runtimes);
    if (defaultRuntime == null || defaultRuntime == RuntimeInfo.NO_RUNTIME_INFO) {
        defaultRuntime = RuntimeCore.getRuntimeInfoCatalog().getDefaultRuntime();
    }
    if (defaultRuntime != null) {
        fRuntimeList.setCheckedElements(new Object[] { defaultRuntime });
    }
    // by default, sort by name
    sortByName();
    fRuntimeList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent evt) {
            enableButtons();
        }
    });
    fRuntimeList.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            if (event.getChecked()) {
                setCheckedRuntime((RuntimeInfo) event.getElement());
            } else {
                setCheckedRuntime(null);
            }
        }
    });
    fRuntimeList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(final DoubleClickEvent e) {
            if (!fRuntimeList.getSelection().isEmpty()) {
                editRuntime();
            }
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final KeyEvent event) {
            if (event.character == SWT.DEL && event.stateMask == 0) {
                removeSelectedRuntimes();
            }
        }
    });
    final Composite buttons = new Composite(parent, SWT.NULL);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);
    buttons.setFont(font);
    fAddButton = createPushButton(buttons, RuntimePreferenceMessages.add);
    fAddButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event evt) {
            addRuntime();
        }
    });
    fEditButton = createPushButton(buttons, RuntimePreferenceMessages.edit);
    fEditButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event evt) {
            editRuntime();
        }
    });
    fDuplicateButton = createPushButton(buttons, RuntimePreferenceMessages.duplicate);
    fDuplicateButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event evt) {
            duplicateRuntime();
        }
    });
    fRemoveButton = createPushButton(buttons, RuntimePreferenceMessages.remove);
    fRemoveButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event evt) {
            removeSelectedRuntimes();
        }
    });
    fDetectButton = createPushButton(buttons, RuntimePreferenceMessages.detect);
    fDetectButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event evt) {
            detectRuntimes();
        }
    });
    configureTableResizing(parent, buttons, table, column1, column2, column3);
    enableButtons();
    return parent;
}
Also used : IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Listener(org.eclipse.swt.widgets.Listener) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Font(org.eclipse.swt.graphics.Font) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableLayout(org.eclipse.jface.viewers.TableLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) RuntimeInfo(org.erlide.runtime.runtimeinfo.RuntimeInfo) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) GridData(org.eclipse.swt.layout.GridData) KeyEvent(org.eclipse.swt.events.KeyEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 12 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project eclipse-cs by checkstyle.

the class ComplexFileSetsEditor method createContents.

/**
 * {@inheritDoc}
 */
@Override
public Control createContents(Composite parent) throws CheckstylePluginException {
    mComposite = parent;
    Group composite = new Group(parent, SWT.NONE);
    composite.setText(Messages.ComplexFileSetsEditor_titleAdvancedFilesetEditor);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    composite.setLayout(layout);
    // 
    // Create the table of file sets.
    // 
    Table table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION);
    GridData data = new GridData(GridData.FILL_BOTH);
    table.setLayoutData(data);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.setText(Messages.ComplexFileSetsEditor_colEnabled);
    column1.setResizable(false);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    column2.setText(Messages.ComplexFileSetsEditor_colFilesetName);
    TableColumn column3 = new TableColumn(table, SWT.NONE);
    column3.setText(Messages.ComplexFileSetsEditor_colConfiguration);
    tableLayout.addColumnData(new ColumnWeightData(20));
    tableLayout.addColumnData(new ColumnWeightData(40));
    tableLayout.addColumnData(new ColumnWeightData(40));
    mViewer = new CheckboxTableViewer(table);
    mViewer.setLabelProvider(new FileSetLabelProvider());
    mViewer.setContentProvider(new ArrayContentProvider());
    mViewer.setComparator(new FileSetViewerSorter());
    mViewer.setInput(mFileSets);
    // 
    for (FileSet fileSet : mFileSets) {
        mViewer.setChecked(fileSet, fileSet.isEnabled());
    }
    mViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent e) {
            editFileSet();
        }
    });
    mViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            changeEnabledState(event);
        }
    });
    // 
    // Build the buttons.
    // 
    Composite buttons = new Composite(composite, SWT.NULL);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);
    mAddButton = createPushButton(buttons, Messages.ComplexFileSetsEditor_btnAdd);
    mAddButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event evt) {
            addFileSet();
        }
    });
    mEditButton = createPushButton(buttons, Messages.ComplexFileSetsEditor_btnEdit);
    mEditButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event evt) {
            editFileSet();
        }
    });
    mRemoveButton = createPushButton(buttons, Messages.ComplexFileSetsEditor_btnRemove);
    mRemoveButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event evt) {
            removeFileSet();
        }
    });
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Listener(org.eclipse.swt.widgets.Listener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 13 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project eclipse-cs by checkstyle.

the class FileSetEditDialog method createFileMatchPatternPart.

private Control createFileMatchPatternPart(Composite parent) {
    Group composite = new Group(parent, SWT.NONE);
    composite.setText(Messages.FileSetEditDialog_titlePatternsTable);
    composite.setLayout(new FormLayout());
    final Composite buttons = new Composite(composite, SWT.NULL);
    FormData fd = new FormData();
    fd.top = new FormAttachment(0, 3);
    fd.right = new FormAttachment(100, -3);
    fd.bottom = new FormAttachment(100, -3);
    buttons.setLayoutData(fd);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);
    final Table table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION);
    fd = new FormData();
    fd.left = new FormAttachment(0, 3);
    fd.top = new FormAttachment(0, 3);
    fd.right = new FormAttachment(buttons, -3, SWT.LEFT);
    fd.bottom = new FormAttachment(100, -3);
    table.setLayoutData(fd);
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.setText(Messages.FileSetEditDialog_colInclude);
    tableLayout.addColumnData(new ColumnWeightData(11));
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    column2.setText(Messages.FileSetEditDialog_colRegex);
    tableLayout.addColumnData(new ColumnWeightData(89));
    mPatternViewer = new CheckboxTableViewer(table);
    mPatternViewer.setLabelProvider(new FileMatchPatternLabelProvider());
    mPatternViewer.setContentProvider(new ArrayContentProvider());
    mPatternViewer.addDoubleClickListener(mController);
    mPatternViewer.addCheckStateListener(mController);
    // 
    // Build the buttons.
    // 
    mAddButton = createPushButton(buttons, Messages.FileSetEditDialog_btnAdd);
    mAddButton.addSelectionListener(mController);
    mEditButton = createPushButton(buttons, Messages.FileSetEditDialog_btnEdit);
    mEditButton.addSelectionListener(mController);
    mRemoveButton = createPushButton(buttons, Messages.FileSetEditDialog_btnRemove);
    mRemoveButton.addSelectionListener(mController);
    mUpButton = createPushButton(buttons, Messages.FileSetEditDialog_btnUp);
    mUpButton.addSelectionListener(mController);
    mDownButton = createPushButton(buttons, Messages.FileSetEditDialog_btnDown);
    mDownButton.addSelectionListener(mController);
    return composite;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableLayout(org.eclipse.jface.viewers.TableLayout) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 14 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project janrufmonitor by tbrandt77.

the class AbstractPhonesPage method createControl.

public void createControl(Composite parent) {
    setTitle(this.m_i18n.getString(getNamespace(), "title", "label", this.m_language));
    setDescription(this.m_i18n.getString(getNamespace(), "description", "label", this.m_language));
    Composite c = new Composite(parent, SWT.NONE);
    c.setLayout(new GridLayout(1, false));
    c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    all = new Button(c, SWT.CHECK);
    all.setText(this.m_i18n.getString(this.getNamespace(), "*", "label", this.m_language));
    all.setSelection((this.getCallers().size() == 0 ? true : false));
    Label ln = new Label(c, SWT.LEFT);
    Composite select = new Composite(c, SWT.NONE);
    select.setLayout(new GridLayout(3, false));
    select.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ln = new Label(select, SWT.LEFT);
    ln.setText(this.m_i18n.getString(this.getNamespace(), "allphones", "label", this.m_language));
    ln = new Label(select, SWT.LEFT);
    ln = new Label(select, SWT.LEFT);
    ln.setText(this.m_i18n.getString(this.getNamespace(), "selectedphones", "label", this.m_language));
    final CheckboxTableViewer call = CheckboxTableViewer.newCheckList(select, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL);
    call.setLabelProvider(new CallerLabelProvider());
    call.setContentProvider(new CallerContentProvider());
    call.setInput(null);
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                progressMonitor.beginTask(m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "refreshprogress", "label", m_language), IProgressMonitor.UNKNOWN);
                final List callers = new ArrayList();
                Thread t = new Thread() {

                    public void run() {
                        // preload data
                        try {
                            callers.addAll(getAllCallers());
                        } catch (Exception ex) {
                            m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                        }
                    }
                };
                t.setName("JAM-ContactsRead-Thread-(non-deamon)");
                t.start();
                int lastamount = -1;
                do {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                    }
                    m_currentCallerManager = CallerReaderFactory.getInstance().getCurrent();
                    if (m_currentCallerManager != null && m_currentCallerManager instanceof ITracker) {
                        int leftover = Math.max(0, (((ITracker) m_currentCallerManager).getTotal() - ((ITracker) m_currentCallerManager).getCurrent()));
                        if (lastamount == leftover) {
                            String msg = m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "working", "label", m_language);
                            progressMonitor.subTask(msg);
                        } else {
                            String msg = m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "tracking", "label", m_language);
                            msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(leftover));
                            if (m_currentCallerManager instanceof IConfigurable) {
                                msg = StringUtils.replaceString(msg, "{%2}", m_i18n.getString(((IConfigurable) m_currentCallerManager).getNamespace(), "title", "label", m_language));
                            } else {
                                msg = StringUtils.replaceString(msg, "{%2}", m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "nocallermanager", "label", m_language));
                            }
                            progressMonitor.subTask(msg);
                        }
                        lastamount = leftover;
                    } else {
                        String msg = m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "notracking", "label", m_language);
                        if (m_currentCallerManager instanceof IConfigurable) {
                            msg = StringUtils.replaceString(msg, "{%1}", m_i18n.getString(((IConfigurable) m_currentCallerManager).getNamespace(), "title", "label", m_language));
                        } else {
                            msg = StringUtils.replaceString(msg, "{%1}", m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "nocallermanager", "label", m_language));
                        }
                        progressMonitor.subTask(msg);
                    }
                } while (t.isAlive());
                SWTExecuter tt = new SWTExecuter("ContactsRefresh") {

                    protected void execute() {
                        call.setInput(callers);
                    }
                };
                tt.start();
                progressMonitor.done();
            }
        };
        pmd.setBlockOnOpen(false);
        pmd.run(true, false, r);
    // ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    GridData gd = new GridData(200, 200);
    call.getTable().setLayoutData(gd);
    Composite btns = new Composite(select, SWT.NONE);
    btns.setLayout(new GridLayout(1, false));
    btns.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    final Button add = new Button(btns, SWT.PUSH);
    add.setText(this.m_i18n.getString(this.getNamespace(), "add", "label", this.m_language));
    final Button remove = new Button(btns, SWT.PUSH);
    remove.setText(this.m_i18n.getString(this.getNamespace(), "remove", "label", this.m_language));
    final CheckboxTableViewer cselect = CheckboxTableViewer.newCheckList(select, SWT.CHECK | SWT.BORDER);
    cselect.setLabelProvider(new CallerLabelProvider());
    cselect.setContentProvider(new CallerContentProvider());
    List selected = this.getCallers();
    cselect.setInput(selected);
    gd = new GridData(200, 200);
    cselect.getTable().setLayoutData(gd);
    all.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            add.setEnabled(!all.getSelection());
            remove.setEnabled(!all.getSelection());
            call.setAllGrayed(all.getSelection());
            cselect.setAllGrayed(all.getSelection());
        }
    });
    add.setEnabled(!all.getSelection());
    remove.setEnabled(!all.getSelection());
    call.setAllGrayed(all.getSelection());
    cselect.setAllGrayed(all.getSelection());
    add.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            Object[] checked = call.getCheckedElements();
            if (checked != null && checked.length > 0) {
                for (int i = 0; i < checked.length; i++) {
                    if (!m_selectedCallers.contains(checked[i]))
                        m_selectedCallers.add(checked[i]);
                }
                cselect.setInput(m_selectedCallers);
            }
        }
    });
    remove.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            Object[] checked = cselect.getCheckedElements();
            if (checked != null && checked.length > 0) {
                for (int i = 0; i < checked.length; i++) {
                    if (m_selectedCallers.contains(checked[i]))
                        m_selectedCallers.remove(checked[i]);
                }
                cselect.setInput(m_selectedCallers);
            }
        }
    });
    setPageComplete(true);
    setControl(c);
}
Also used : ITracker(de.janrufmonitor.repository.imexport.ITracker) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) IConfigurable(de.janrufmonitor.framework.configuration.IConfigurable) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 15 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project egit by eclipse.

the class ExistingOrNewPage method createControl.

@Override
public void createControl(Composite parent) {
    final RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
    Composite main = new Composite(parent, SWT.NONE);
    // use zero spacing to save some real estate here
    GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(main);
    final Button internalModeButton = new Button(main, SWT.CHECK);
    internalModeButton.setText(UIText.ExistingOrNewPage_InternalModeCheckbox);
    internalModeButton.setToolTipText(UIText.ExistingOrNewPage_CreationInWorkspaceWarningTooltip);
    internalModeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            internalMode = internalModeButton.getSelection();
            updateControls();
        }
    });
    externalComposite = new Composite(main, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(externalComposite);
    externalComposite.setLayout(new GridLayout(3, false));
    new Label(externalComposite, SWT.NONE).setText(UIText.ExistingOrNewPage_ExistingRepositoryLabel);
    final Combo existingRepoCombo = new Combo(externalComposite, SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(existingRepoCombo);
    final ComboViewer v = new ComboViewer(existingRepoCombo);
    v.setContentProvider(new RepoComboContentProvider());
    v.setLabelProvider(new RepoComboLabelProvider());
    v.setInput(new Object());
    // the default ViewerSorter seems to do the right thing
    // i.e. sort as String
    v.setComparator(new ViewerComparator());
    existingRepoCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedRepository = null;
            IStructuredSelection sel = (IStructuredSelection) v.getSelection();
            setRepository((Repository) sel.getFirstElement());
            updateControls();
        }
    });
    Button createRepoWizard = new Button(externalComposite, SWT.PUSH);
    createRepoWizard.setText(UIText.ExistingOrNewPage_CreateRepositoryButton);
    createRepoWizard.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            NewRepositoryWizard wiz = new NewRepositoryWizard(true);
            if (new WizardDialog(getShell(), wiz).open() == Window.OK) {
                v.refresh();
                selectedRepository = wiz.getCreatedRepository();
                v.setSelection(new StructuredSelection(selectedRepository));
                updateControls();
            }
        }
    });
    new Label(externalComposite, SWT.NONE).setText(UIText.ExistingOrNewPage_WorkingDirectoryLabel);
    workDir = new Text(externalComposite, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(workDir);
    GridDataFactory.fillDefaults().applyTo(workDir);
    // leave the space between the "Create" and "Browse" buttons empty (i.e.
    // do not fill to the right border
    new Label(externalComposite, SWT.NONE);
    new Label(externalComposite, SWT.NONE).setText(UIText.ExistingOrNewPage_RelativePathLabel);
    relPath = new Text(externalComposite, SWT.BORDER);
    relPath.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateControls();
        }
    });
    GridDataFactory.fillDefaults().grab(true, false).applyTo(relPath);
    browseRepository = new Button(externalComposite, SWT.PUSH);
    browseRepository.setEnabled(false);
    browseRepository.setText(UIText.ExistingOrNewPage_BrowseRepositoryButton);
    browseRepository.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            dlg.setMessage(UIText.ExistingOrNewPage_title);
            dlg.setFilterPath(selectedRepository.getWorkTree().getPath());
            String directory = dlg.open();
            if (directory != null) {
                setRelativePath(directory);
                updateControls();
            }
        }
    });
    Table projectMoveTable = new Table(externalComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK | SWT.BORDER);
    projectMoveViewer = new CheckboxTableViewer(projectMoveTable);
    GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(projectMoveTable);
    TableColumn tc;
    tc = new TableColumn(projectMoveTable, SWT.NONE);
    tc.setText(UIText.ExistingOrNewPage_ProjectNameColumnHeader);
    tc.setWidth(100);
    tc = new TableColumn(projectMoveTable, SWT.NONE);
    tc.setText(UIText.ExistingOrNewPage_CurrentLocationColumnHeader);
    tc.setWidth(250);
    tc = new TableColumn(projectMoveTable, SWT.NONE);
    tc.setText(UIText.ExistingOrNewPage_NewLocationTargetHeader);
    tc.setWidth(350);
    projectMoveTable.setHeaderVisible(true);
    projectMoveViewer.setContentProvider(ArrayContentProvider.getInstance());
    projectMoveViewer.setLabelProvider(moveProjectsLabelProvider);
    projectMoveViewer.setInput(myWizard.projects);
    projectMoveViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateControls();
        }
    });
    TableItem[] children = projectMoveViewer.getTable().getItems();
    for (int i = 0; i < children.length; i++) {
        TableItem item = children[i];
        IProject data = (IProject) item.getData();
        RepositoryFinder repositoryFinder = new RepositoryFinder(data);
        repositoryFinder.setFindInChildren(false);
        try {
            Collection<RepositoryMapping> find = repositoryFinder.find(new NullProgressMonitor());
            if (find.size() != 1)
                item.setChecked(true);
        } catch (CoreException e1) {
            item.setText(2, e1.getMessage());
        }
    }
    parentRepoComposite = new Composite(main, SWT.NONE);
    parentRepoComposite.setLayout(new GridLayout(3, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parentRepoComposite);
    tree = new Tree(parentRepoComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
    viewer = new CheckboxTreeViewer(tree);
    tree.setHeaderVisible(true);
    tree.setLayout(new GridLayout());
    tree.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(3, 1).create());
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
                ProjectAndRepo checkable = (ProjectAndRepo) event.getElement();
                for (TreeItem ti : tree.getItems()) {
                    if (ti.getItemCount() > 0 || ((ProjectAndRepo) ti.getData()).getRepo().equals(// $NON-NLS-1$
                    ""))
                        ti.setChecked(false);
                    for (TreeItem subTi : ti.getItems()) {
                        IProject project = ((ProjectAndRepo) subTi.getData()).getProject();
                        if (checkable.getProject() != null && !subTi.getData().equals(checkable) && checkable.getProject().equals(project))
                            subTi.setChecked(false);
                    }
                }
            }
        }
    });
    TreeColumn c1 = new TreeColumn(tree, SWT.NONE);
    c1.setText(UIText.ExistingOrNewPage_HeaderProject);
    c1.setWidth(100);
    TreeColumn c2 = new TreeColumn(tree, SWT.NONE);
    c2.setText(UIText.ExistingOrNewPage_HeaderLocation);
    c2.setWidth(400);
    TreeColumn c3 = new TreeColumn(tree, SWT.NONE);
    c3.setText(UIText.ExistingOrNewPage_HeaderRepository);
    c3.setWidth(200);
    boolean allProjectsInExistingRepos = true;
    for (IProject project : myWizard.projects) {
        RepositoryFinder repositoryFinder = new RepositoryFinder(project);
        repositoryFinder.setFindInChildren(false);
        try {
            Collection<RepositoryMapping> mappings;
            mappings = repositoryFinder.find(new NullProgressMonitor());
            Iterator<RepositoryMapping> mi = mappings.iterator();
            RepositoryMapping m = mi.hasNext() ? mi.next() : null;
            if (m == null) {
                // no mapping found, enable repository creation
                TreeItem treeItem = new TreeItem(tree, SWT.NONE);
                updateProjectTreeItem(treeItem, project);
                treeItem.setText(1, project.getLocation().toOSString());
                // $NON-NLS-1$
                treeItem.setText(2, "");
                // $NON-NLS-1$
                treeItem.setData(new ProjectAndRepo(project, ""));
                allProjectsInExistingRepos = false;
            } else if (!mi.hasNext()) {
                // exactly one mapping found
                IPath path = m.getGitDirAbsolutePath();
                if (path != null) {
                    TreeItem treeItem = new TreeItem(tree, SWT.NONE);
                    updateProjectTreeItem(treeItem, project);
                    treeItem.setText(1, project.getLocation().toOSString());
                    fillTreeItemWithGitDirectory(m, treeItem, path, false);
                    treeItem.setData(new ProjectAndRepo(project, path.toOSString()));
                    treeItem.setChecked(true);
                }
            } else {
                IPath path = m.getGitDirAbsolutePath();
                if (path != null) {
                    TreeItem treeItem = new TreeItem(tree, SWT.NONE);
                    updateProjectTreeItem(treeItem, project);
                    treeItem.setText(1, project.getLocation().toOSString());
                    // $NON-NLS-1$
                    treeItem.setData(new ProjectAndRepo(project, ""));
                    TreeItem treeItem2 = new TreeItem(treeItem, SWT.NONE);
                    updateProjectTreeItem(treeItem2, project);
                    fillTreeItemWithGitDirectory(m, treeItem2, path, true);
                    treeItem2.setData(new ProjectAndRepo(project, path.toOSString()));
                    while (mi.hasNext()) {
                        // fill in additional mappings
                        m = mi.next();
                        path = m.getGitDirAbsolutePath();
                        if (path != null) {
                            treeItem2 = new TreeItem(treeItem, SWT.NONE);
                            updateProjectTreeItem(treeItem2, project);
                            fillTreeItemWithGitDirectory(m, treeItem2, path, true);
                            treeItem2.setData(new ProjectAndRepo(m.getContainer().getProject(), path.toOSString()));
                        }
                    }
                    treeItem.setExpanded(true);
                }
                allProjectsInExistingRepos = false;
            }
        } catch (CoreException e) {
            TreeItem treeItem2 = new TreeItem(tree, SWT.BOLD | SWT.ITALIC);
            treeItem2.setText(e.getMessage());
        }
    }
    createRepo = new Button(parentRepoComposite, SWT.PUSH);
    createRepo.setLayoutData(GridDataFactory.fillDefaults().create());
    createRepo.setText(UIText.ExistingOrNewPage_CreateButton);
    createRepo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            File gitDir = new File(repositoryToCreate.getText(), Constants.DOT_GIT);
            try {
                Repository repository = FileRepositoryBuilder.create(gitDir);
                repository.create();
                for (IProject project : getProjects(false).keySet()) {
                    // 
                    if (// $NON-NLS-1$
                    !gitDir.toString().contains(".."))
                        project.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
                }
                util.addConfiguredRepository(gitDir);
            } catch (IOException e1) {
                String msg = NLS.bind(UIText.ExistingOrNewPage_ErrorFailedToCreateRepository, gitDir.toString());
                org.eclipse.egit.ui.Activator.handleError(msg, e1, true);
            } catch (CoreException e2) {
                String msg = NLS.bind(UIText.ExistingOrNewPage_ErrorFailedToRefreshRepository, gitDir);
                org.eclipse.egit.ui.Activator.handleError(msg, e2, true);
            }
            for (TreeItem ti : tree.getSelection()) {
                IPath projectPath = new Path(ti.getText(1));
                IPath gitPath = new Path(gitDir.toString());
                IPath relative = gitPath.makeRelativeTo(projectPath);
                ti.setText(2, relative.toOSString());
                ((ProjectAndRepo) ti.getData()).repo = gitDir.toString();
                ti.setChecked(true);
            }
            updateControls();
        }
    });
    repositoryToCreate = new Text(parentRepoComposite, SWT.SINGLE | SWT.BORDER);
    repositoryToCreate.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(1, 1).create());
    repositoryToCreate.addListener(SWT.Modify, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (repositoryToCreate.getText().equals("")) {
                // $NON-NLS-1$
                createRepo.setEnabled(false);
                return;
            }
            IPath fromOSString = Path.fromOSString(repositoryToCreate.getText());
            createRepo.setEnabled(minumumPath.matchingFirstSegments(fromOSString) == fromOSString.segmentCount());
        }
    });
    dotGitSegment = new Label(parentRepoComposite, SWT.NONE);
    dotGitSegment.setEnabled(false);
    dotGitSegment.setText(File.separatorChar + Constants.DOT_GIT);
    dotGitSegment.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).create());
    tree.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tree.select((TreeItem) e.item);
            updateControls();
        }
    });
    Dialog.applyDialogFont(main);
    setControl(main);
    if (allProjectsInExistingRepos) {
        internalMode = true;
        internalModeButton.setSelection(true);
        updateControls();
    }
}
Also used : CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) TreeItem(org.eclipse.swt.widgets.TreeItem) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) RepositoryFinder(org.eclipse.egit.core.project.RepositoryFinder) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Combo(org.eclipse.swt.widgets.Combo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RevTree(org.eclipse.jgit.revwalk.RevTree) Tree(org.eclipse.swt.widgets.Tree) IPath(org.eclipse.core.runtime.IPath) TableColumn(org.eclipse.swt.widgets.TableColumn) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CoreException(org.eclipse.core.runtime.CoreException) ComboViewer(org.eclipse.jface.viewers.ComboViewer) File(java.io.File) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) NewRepositoryWizard(org.eclipse.egit.ui.internal.repository.NewRepositoryWizard) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) Repository(org.eclipse.jgit.lib.Repository) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)45 Composite (org.eclipse.swt.widgets.Composite)29 Table (org.eclipse.swt.widgets.Table)28 GridData (org.eclipse.swt.layout.GridData)24 GridLayout (org.eclipse.swt.layout.GridLayout)21 Label (org.eclipse.swt.widgets.Label)20 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)19 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)19 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 TableColumn (org.eclipse.swt.widgets.TableColumn)17 Button (org.eclipse.swt.widgets.Button)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)10 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)8 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)8 SelectionListener (org.eclipse.swt.events.SelectionListener)7 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)6 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)6 Viewer (org.eclipse.jface.viewers.Viewer)6 Event (org.eclipse.swt.widgets.Event)6