Search in sources :

Example 1 with SVNPluginAction

use of org.tigris.subversion.subclipse.ui.actions.SVNPluginAction in project subclipse by subclipse.

the class SvnWizardCommitPage method addResourcesArea.

private void addResourcesArea(Composite composite) {
    // get the toolbar actions from any contributing plug-in
    final SVNPluginAction[] toolbarActions = SVNUIPlugin.getCommitDialogToolBarActions();
    final SVNPluginAction[] alternateCompareActions = SVNUIPlugin.getCommitDialogCompareActions();
    ResourceSelectionTree.IToolbarControlCreator toolbarControlCreator = new ResourceSelectionTree.IToolbarControlCreator() {

        public void createToolbarControls(ToolBarManager toolbarManager) {
            toolbarManager.add(new // $NON-NLS-1$
            ControlContribution(// $NON-NLS-1$
            "ignoreUnversioned") {

                protected Control createControl(Composite parent) {
                    includeUnversionedButton = new Button(parent, SWT.CHECK);
                    includeUnversionedButton.setText(// $NON-NLS-1$
                    Policy.bind("CommitDialog.includeUnversioned"));
                    includeUnversionedButton.setSelection(includeUnversioned);
                    includeUnversionedButton.addSelectionListener(new SelectionListener() {

                        public void widgetSelected(SelectionEvent e) {
                            includeUnversioned = includeUnversionedButton.getSelection();
                            includeUnversionedAction.setChecked(includeUnversioned);
                            toggleIncludeUnversioned();
                        }

                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                    });
                    return includeUnversionedButton;
                }
            });
            toolbarManager.add(new ControlContribution("keepLocks") {

                protected Control createControl(Composite parent) {
                    keepLocksButton = new Button(parent, SWT.CHECK);
                    // $NON-NLS-1$
                    keepLocksButton.setText(Policy.bind("CommitDialog.keepLocks"));
                    keepLocksButton.addSelectionListener(new SelectionListener() {

                        public void widgetSelected(SelectionEvent e) {
                            keepLocks = keepLocksButton.getSelection();
                            keepLocksAction.setChecked(keepLocksButton.getSelection());
                        }

                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                    });
                    return keepLocksButton;
                }
            });
            toolbarManager.add(new Separator());
            toolbarManager.add(new ControlContribution("showCompare") {

                protected Control createControl(Composite parent) {
                    showCompareButton = new Button(parent, SWT.TOGGLE | SWT.FLAT);
                    showCompareButton.setImage(// $NON-NLS-1$
                    SVNUIPlugin.getImage(ISVNUIConstants.IMG_SYNCPANE));
                    showCompareButton.setToolTipText(Policy.bind("CommitDialog.showCompare"));
                    showCompareButton.setSelection(showCompare);
                    showCompareButton.addSelectionListener(new SelectionListener() {

                        public void widgetSelected(SelectionEvent e) {
                            showComparePane(!showCompare);
                            if (showCompare) {
                                IStructuredSelection selection = (IStructuredSelection) resourceSelectionTree.getTreeViewer().getSelection();
                                if (!selection.isEmpty()) {
                                    Object sel0 = selection.getFirstElement();
                                    if (sel0 instanceof IFile) {
                                        final ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor((IFile) sel0);
                                        try {
                                            // compare dialog
                                            if (alternateCompareActions.length > 0) {
                                                StructuredSelection localResourceSelection = new StructuredSelection(localResource);
                                                for (int i = 0; i < alternateCompareActions.length; i++) {
                                                    // make sure the selection is up to date
                                                    alternateCompareActions[i].selectionChanged(localResourceSelection);
                                                    alternateCompareActions[i].run();
                                                }
                                            } else {
                                                setCompareInput(new SVNLocalCompareInput(localResource, SVNRevision.BASE, true));
                                            }
                                        } catch (Exception e1) {
                                        }
                                    }
                                }
                            }
                        }

                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                    });
                    return showCompareButton;
                }
            });
            // add any contributing actions from the extension point
            if (toolbarActions.length > 0) {
                toolbarManager.add(new Separator());
                for (int i = 0; i < toolbarActions.length; i++) {
                    SVNPluginAction action = toolbarActions[i];
                    toolbarManager.add(action);
                }
            }
        }

        public int getControlCount() {
            return 1;
        }
    };
    resourceSelectionTree = new ResourceSelectionTree(composite, SWT.NONE, Policy.bind("GenerateSVNDiff.Changes"), ResourceSelectionTree.dedupeResources(resourcesToCommit), statusMap, null, true, toolbarControlCreator, // $NON-NLS-1$
    syncInfoSet);
    if (!resourceSelectionTree.showIncludeUnversionedButton())
        includeUnversionedButton.setVisible(false);
    resourceSelectionTree.setCustomOptions(getCustomOptions());
    resourceSelectionTree.setRemoveFromViewValidator(new ResourceSelectionTree.IRemoveFromViewValidator() {

        public boolean canRemove(ArrayList resourceList, IStructuredSelection selection) {
            return removalOk(resourceList, selection);
        }

        public String getErrorMessage() {
            return removalError;
        // return Policy.bind("CommitDialog.unselectedPropChangeChildren"); //$NON-NLS-1$
        }
    });
    resourceSelectionTree.getTreeViewer().getTree().addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            selectedResources = resourceSelectionTree.getSelectedResources();
            // need to update the toolbar actions too - but we use the tree viewer's selection
            IStructuredSelection selection = (IStructuredSelection) resourceSelectionTree.getTreeViewer().getSelection();
            if (toolbarActions.length > 0) {
                for (int i = 0; i < toolbarActions.length; i++) {
                    SVNPluginAction action = toolbarActions[i];
                    action.selectionChanged(selection);
                }
            }
            if (showCompare) {
                Object sel0 = selection.getFirstElement();
                if (sel0 instanceof IFile) {
                    final ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor((IFile) sel0);
                    try {
                        // then call those actions instead of showing the default compare dialog
                        if (alternateCompareActions.length > 0) {
                            StructuredSelection localResourceSelection = new StructuredSelection(localResource);
                            for (int i = 0; i < alternateCompareActions.length; i++) {
                                // make sure the selection is up to date
                                alternateCompareActions[i].selectionChanged(localResourceSelection);
                                alternateCompareActions[i].run();
                            }
                        } else {
                            setCompareInput(new SVNLocalCompareInput(localResource, SVNRevision.BASE, true));
                        }
                    } catch (Exception e1) {
                    }
                }
            }
        }
    });
    ((CheckboxTreeViewer) resourceSelectionTree.getTreeViewer()).addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            selectedResources = resourceSelectionTree.getSelectedResources();
        }
    });
    resourceSelectionTree.getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            Object sel0 = sel.getFirstElement();
            if (sel0 instanceof IFile) {
                final ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor((IFile) sel0);
                try {
                    // then call those actions instead of showing the default compare dialog
                    if (alternateCompareActions.length > 0) {
                        StructuredSelection selection = new StructuredSelection(localResource);
                        for (int i = 0; i < alternateCompareActions.length; i++) {
                            // make sure the selection is up to date
                            alternateCompareActions[i].selectionChanged(selection);
                            alternateCompareActions[i].run();
                        }
                    } else {
                        setCompareInput(new SVNLocalCompareInput(localResource, SVNRevision.BASE, true));
                        showComparePane(true);
                        showCompareButton.setSelection(true);
                    }
                } catch (Exception e1) {
                }
            }
        }
    });
    if (!includeUnversioned) {
        resourceSelectionTree.removeUnversioned();
    }
    selectedResources = resourceSelectionTree.getSelectedResources();
    setPageComplete(canFinish());
}
Also used : IFile(org.eclipse.core.resources.IFile) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) ControlContribution(org.eclipse.jface.action.ControlContribution) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ToolBarManager(org.eclipse.jface.action.ToolBarManager) Control(org.eclipse.swt.widgets.Control) ResourceSelectionTree(org.tigris.subversion.subclipse.ui.util.ResourceSelectionTree) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SVNException(org.tigris.subversion.subclipse.core.SVNException) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) SVNPluginAction(org.tigris.subversion.subclipse.ui.actions.SVNPluginAction) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Separator(org.eclipse.jface.action.Separator) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with SVNPluginAction

use of org.tigris.subversion.subclipse.ui.actions.SVNPluginAction in project subclipse by subclipse.

the class SVNUIPlugin method getCommitDialogCompareActions.

/**
 * Returns the commit dialog compare actions found from the extension point.
 */
public static SVNPluginAction[] getCommitDialogCompareActions() {
    if (commitDialogCompareActions == null) {
        ArrayList actionsList = new ArrayList();
        IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(COMMIT_DIALOG_COMPARE_ACTIONS);
        for (int i = 0; i < elements.length; i++) {
            SVNPluginAction action = new SVNPluginAction(elements[i]);
            if (action.getDelegate() != null) {
                actionsList.add(action);
            }
        }
        commitDialogCompareActions = new SVNPluginAction[actionsList.size()];
        actionsList.toArray(commitDialogCompareActions);
    }
    return commitDialogCompareActions;
}
Also used : SVNPluginAction(org.tigris.subversion.subclipse.ui.actions.SVNPluginAction) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 3 with SVNPluginAction

use of org.tigris.subversion.subclipse.ui.actions.SVNPluginAction in project subclipse by subclipse.

the class SVNUIPlugin method getCommitDialogToolBarActions.

/**
 * Returns all the commit dialog toolbar actions that were found from the extension point.
 */
public static SVNPluginAction[] getCommitDialogToolBarActions() {
    if (commitDialogToolBarActions == null) {
        ArrayList actionsList = new ArrayList();
        IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(COMMIT_DIALOG_TOOLBAR_ACTIONS);
        for (int i = 0; i < elements.length; i++) {
            SVNPluginAction action = new SVNPluginAction(elements[i]);
            if (action.getDelegate() != null) {
                actionsList.add(action);
            }
        }
        commitDialogToolBarActions = new SVNPluginAction[actionsList.size()];
        actionsList.toArray(commitDialogToolBarActions);
    }
    return commitDialogToolBarActions;
}
Also used : SVNPluginAction(org.tigris.subversion.subclipse.ui.actions.SVNPluginAction) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Aggregations

ArrayList (java.util.ArrayList)3 SVNPluginAction (org.tigris.subversion.subclipse.ui.actions.SVNPluginAction)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IFile (org.eclipse.core.resources.IFile)1 ControlContribution (org.eclipse.jface.action.ControlContribution)1 Separator (org.eclipse.jface.action.Separator)1 ToolBarManager (org.eclipse.jface.action.ToolBarManager)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1