Search in sources :

Example 46 with ControlListener

use of org.eclipse.swt.events.ControlListener in project egit by eclipse.

the class StagingView method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    GridLayoutFactory.fillDefaults().applyTo(parent);
    toolkit = new FormToolkit(parent.getDisplay());
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (commitMessageComponent.isAmending() || userEnteredCommitMessage())
                saveCommitMessageComponentState();
            else
                deleteCommitMessageComponentState();
            resources.dispose();
            toolkit.dispose();
        }
    });
    form = toolkit.createForm(parent);
    parent.addControlListener(new ControlListener() {

        private int[] defaultWeights = { 1, 1 };

        @Override
        public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle b = parent.getBounds();
            int oldOrientation = mainSashForm.getOrientation();
            if ((oldOrientation == SWT.HORIZONTAL) && (b.height > b.width)) {
                mainSashForm.setOrientation(SWT.VERTICAL);
                mainSashForm.setWeights(defaultWeights);
            } else if ((oldOrientation == SWT.VERTICAL) && (b.height <= b.width)) {
                mainSashForm.setOrientation(SWT.HORIZONTAL);
                mainSashForm.setWeights(defaultWeights);
            }
        }

        @Override
        public void controlMoved(ControlEvent e) {
        // ignore
        }
    });
    form.setImage(getImage(UIIcons.REPOSITORY));
    form.setText(UIText.StagingView_NoSelectionTitle);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(form);
    toolkit.decorateFormHeading(form);
    GridLayoutFactory.swtDefaults().applyTo(form.getBody());
    mainSashForm = new SashForm(form.getBody(), SWT.HORIZONTAL);
    saveSashFormWeightsOnDisposal(mainSashForm, HORIZONTAL_SASH_FORM_WEIGHT);
    toolkit.adapt(mainSashForm, true, true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(mainSashForm);
    stagingSashForm = new SashForm(mainSashForm, getStagingFormOrientation());
    saveSashFormWeightsOnDisposal(stagingSashForm, STAGING_SASH_FORM_WEIGHT);
    toolkit.adapt(stagingSashForm, true, true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(stagingSashForm);
    unstageAction = new Action(UIText.StagingView_UnstageItemMenuLabel, UIIcons.UNSTAGE) {

        @Override
        public void run() {
            unstage((IStructuredSelection) stagedViewer.getSelection());
        }
    };
    unstageAction.setToolTipText(UIText.StagingView_UnstageItemTooltip);
    stageAction = new Action(UIText.StagingView_StageItemMenuLabel, UIIcons.ELCL16_ADD) {

        @Override
        public void run() {
            stage((IStructuredSelection) unstagedViewer.getSelection());
        }
    };
    stageAction.setToolTipText(UIText.StagingView_StageItemTooltip);
    unstageAction.setEnabled(false);
    stageAction.setEnabled(false);
    unstageAllAction = new Action(UIText.StagingView_UnstageAllItemMenuLabel, UIIcons.UNSTAGE_ALL) {

        @Override
        public void run() {
            stagedViewer.getTree().selectAll();
            unstage((IStructuredSelection) stagedViewer.getSelection());
        }
    };
    unstageAllAction.setToolTipText(UIText.StagingView_UnstageAllItemTooltip);
    stageAllAction = new Action(UIText.StagingView_StageAllItemMenuLabel, UIIcons.ELCL16_ADD_ALL) {

        @Override
        public void run() {
            unstagedViewer.getTree().selectAll();
            stage((IStructuredSelection) unstagedViewer.getSelection());
        }
    };
    stageAllAction.setToolTipText(UIText.StagingView_StageAllItemTooltip);
    unstageAllAction.setEnabled(false);
    stageAllAction.setEnabled(false);
    unstagedSection = toolkit.createSection(stagingSashForm, ExpandableComposite.SHORT_TITLE_BAR);
    unstagedSection.clientVerticalSpacing = 0;
    unstagedSection.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    createUnstagedToolBarComposite();
    Composite unstagedComposite = toolkit.createComposite(unstagedSection);
    toolkit.paintBordersFor(unstagedComposite);
    unstagedSection.setClient(unstagedComposite);
    GridLayoutFactory.fillDefaults().applyTo(unstagedComposite);
    unstagedViewer = createViewer(unstagedComposite, true, selection -> unstage(selection), stageAction);
    unstagedViewer.addSelectionChangedListener(event -> {
        boolean hasSelection = !event.getSelection().isEmpty();
        if (hasSelection != stageAction.isEnabled()) {
            stageAction.setEnabled(hasSelection);
            unstagedToolBarManager.update(true);
        }
    });
    Composite rebaseAndCommitComposite = toolkit.createComposite(mainSashForm);
    rebaseAndCommitComposite.setLayout(GridLayoutFactory.fillDefaults().create());
    rebaseSection = toolkit.createSection(rebaseAndCommitComposite, ExpandableComposite.SHORT_TITLE_BAR);
    rebaseSection.clientVerticalSpacing = 0;
    rebaseSection.setText(UIText.StagingView_RebaseLabel);
    Composite rebaseComposite = toolkit.createComposite(rebaseSection);
    toolkit.paintBordersFor(rebaseComposite);
    rebaseSection.setClient(rebaseComposite);
    rebaseSection.setLayoutData(GridDataFactory.fillDefaults().create());
    rebaseComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(true).create());
    GridDataFactory buttonGridData = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER);
    this.rebaseAbortButton = toolkit.createButton(rebaseComposite, UIText.StagingView_RebaseAbort, SWT.PUSH);
    rebaseAbortButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            rebaseAbort();
        }
    });
    rebaseAbortButton.setImage(getImage(UIIcons.REBASE_ABORT));
    buttonGridData.applyTo(rebaseAbortButton);
    this.rebaseSkipButton = toolkit.createButton(rebaseComposite, UIText.StagingView_RebaseSkip, SWT.PUSH);
    rebaseSkipButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            rebaseSkip();
        }
    });
    rebaseSkipButton.setImage(getImage(UIIcons.REBASE_SKIP));
    buttonGridData.applyTo(rebaseSkipButton);
    this.rebaseContinueButton = toolkit.createButton(rebaseComposite, UIText.StagingView_RebaseContinue, SWT.PUSH);
    rebaseContinueButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            rebaseContinue();
        }
    });
    rebaseContinueButton.setImage(getImage(UIIcons.REBASE_CONTINUE));
    buttonGridData.applyTo(rebaseContinueButton);
    showControl(rebaseSection, false);
    commitMessageSection = toolkit.createSection(rebaseAndCommitComposite, ExpandableComposite.SHORT_TITLE_BAR);
    commitMessageSection.clientVerticalSpacing = 0;
    commitMessageSection.setText(UIText.StagingView_CommitMessage);
    commitMessageSection.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    Composite commitMessageToolbarComposite = toolkit.createComposite(commitMessageSection);
    commitMessageToolbarComposite.setBackground(null);
    commitMessageToolbarComposite.setLayout(createRowLayoutWithoutMargin());
    commitMessageSection.setTextClient(commitMessageToolbarComposite);
    ToolBarManager commitMessageToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
    amendPreviousCommitAction = new Action(UIText.StagingView_Ammend_Previous_Commit, IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            commitMessageComponent.setAmendingButtonSelection(isChecked());
            updateMessage();
        }
    };
    amendPreviousCommitAction.setImageDescriptor(UIIcons.AMEND_COMMIT);
    commitMessageToolBarManager.add(amendPreviousCommitAction);
    signedOffByAction = new Action(UIText.StagingView_Add_Signed_Off_By, IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            commitMessageComponent.setSignedOffButtonSelection(isChecked());
        }
    };
    signedOffByAction.setImageDescriptor(UIIcons.SIGNED_OFF);
    commitMessageToolBarManager.add(signedOffByAction);
    addChangeIdAction = new Action(UIText.StagingView_Add_Change_ID, IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            commitMessageComponent.setChangeIdButtonSelection(isChecked());
        }
    };
    addChangeIdAction.setImageDescriptor(UIIcons.GERRIT);
    commitMessageToolBarManager.add(addChangeIdAction);
    commitMessageToolBarManager.createControl(commitMessageToolbarComposite);
    Composite commitMessageComposite = toolkit.createComposite(commitMessageSection);
    commitMessageSection.setClient(commitMessageComposite);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(commitMessageComposite);
    warningLabel = new ToggleableWarningLabel(commitMessageComposite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).exclude(true).applyTo(warningLabel);
    Composite commitMessageTextComposite = toolkit.createComposite(commitMessageComposite);
    toolkit.paintBordersFor(commitMessageTextComposite);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(commitMessageTextComposite);
    GridLayoutFactory.fillDefaults().numColumns(1).extendedMargins(2, 2, 2, 2).applyTo(commitMessageTextComposite);
    final CommitProposalProcessor commitProposalProcessor = new CommitProposalProcessor() {

        @Override
        protected Collection<String> computeFileNameProposals() {
            return getStagedFileNames();
        }

        @Override
        protected Collection<String> computeMessageProposals() {
            return CommitMessageHistory.getCommitHistory();
        }
    };
    commitMessageText = new CommitMessageArea(commitMessageTextComposite, EMPTY_STRING, SWT.NONE) {

        @Override
        protected CommitProposalProcessor getCommitProposalProcessor() {
            return commitProposalProcessor;
        }

        @Override
        protected IHandlerService getHandlerService() {
            return CommonUtils.getService(getSite(), IHandlerService.class);
        }
    };
    commitMessageText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(commitMessageText);
    UIUtils.addBulbDecorator(commitMessageText.getTextWidget(), UIText.CommitDialog_ContentAssist);
    Composite composite = toolkit.createComposite(commitMessageComposite);
    toolkit.paintBordersFor(composite);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(composite);
    toolkit.createLabel(composite, UIText.StagingView_Author).setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    authorText = toolkit.createText(composite, null);
    authorText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    authorText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    toolkit.createLabel(composite, UIText.StagingView_Committer).setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    committerText = toolkit.createText(composite, null);
    committerText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    committerText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    Composite buttonsContainer = toolkit.createComposite(composite);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).indent(0, 8).applyTo(buttonsContainer);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(buttonsContainer);
    ignoreErrors = toolkit.createButton(buttonsContainer, UIText.StagingView_IgnoreErrors, SWT.CHECK);
    ignoreErrors.setSelection(false);
    ignoreErrors.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateMessage();
            updateCommitButtons();
        }
    });
    getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (isDisposed()) {
                getPreferenceStore().removePropertyChangeListener(this);
                return;
            }
            asyncExec(() -> {
                updateIgnoreErrorsButtonVisibility();
                updateMessage();
                updateCommitButtons();
            });
        }
    });
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(true, true).applyTo(ignoreErrors);
    updateIgnoreErrorsButtonVisibility();
    // $NON-NLS-1$
    Label filler = toolkit.createLabel(buttonsContainer, "");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(filler);
    Composite commitButtonsContainer = toolkit.createComposite(buttonsContainer);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(commitButtonsContainer);
    GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true).applyTo(commitButtonsContainer);
    this.commitAndPushButton = toolkit.createButton(commitButtonsContainer, UIText.StagingView_CommitAndPush, SWT.PUSH);
    commitAndPushButton.setImage(getImage(UIIcons.PUSH));
    commitAndPushButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            commit(true);
        }
    });
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(commitAndPushButton);
    this.commitButton = toolkit.createButton(commitButtonsContainer, UIText.StagingView_Commit, SWT.PUSH);
    commitButton.setImage(getImage(UIIcons.COMMIT));
    commitButton.setText(UIText.StagingView_Commit);
    commitButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            commit(false);
        }
    });
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(commitButton);
    stagedSection = toolkit.createSection(stagingSashForm, ExpandableComposite.SHORT_TITLE_BAR);
    stagedSection.clientVerticalSpacing = 0;
    createStagedToolBarComposite();
    Composite stagedComposite = toolkit.createComposite(stagedSection);
    toolkit.paintBordersFor(stagedComposite);
    stagedSection.setClient(stagedComposite);
    GridLayoutFactory.fillDefaults().applyTo(stagedComposite);
    stagedViewer = createViewer(stagedComposite, false, selection -> stage(selection), unstageAction);
    stagedViewer.getLabelProvider().addListener(event -> {
        updateMessage();
        updateCommitButtons();
    });
    stagedViewer.addSelectionChangedListener(event -> {
        boolean hasSelection = !event.getSelection().isEmpty();
        if (hasSelection != unstageAction.isEnabled()) {
            unstageAction.setEnabled(hasSelection);
            stagedToolBarManager.update(true);
        }
    });
    selectionChangedListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (part == getSite().getPart()) {
                return;
            }
            // don't accept text selection, only structural one
            if (selection instanceof StructuredSelection) {
                reactOnSelection((StructuredSelection) selection);
            }
        }
    };
    partListener = new PartListener();
    IPreferenceStore preferenceStore = getPreferenceStore();
    if (preferenceStore.contains(UIPreferences.STAGING_VIEW_SYNC_SELECTION))
        reactOnSelection = preferenceStore.getBoolean(UIPreferences.STAGING_VIEW_SYNC_SELECTION);
    else
        preferenceStore.setDefault(UIPreferences.STAGING_VIEW_SYNC_SELECTION, true);
    preferenceStore.addPropertyChangeListener(uiPrefsListener);
    InstanceScope.INSTANCE.getNode(org.eclipse.egit.core.Activator.getPluginId()).addPreferenceChangeListener(prefListener);
    updateSectionText();
    stagedSection.setToolTipText(UIText.StagingView_StagedChangesTooltip);
    unstagedSection.setToolTipText(UIText.StagingView_UnstagedChangesTooltip);
    updateToolbar();
    enableCommitWidgets(false);
    refreshAction.setEnabled(false);
    createPopupMenu(unstagedViewer);
    createPopupMenu(stagedViewer);
    final ICommitMessageComponentNotifications listener = new ICommitMessageComponentNotifications() {

        @Override
        public void updateSignedOffToggleSelection(boolean selection) {
            signedOffByAction.setChecked(selection);
        }

        @Override
        public void updateChangeIdToggleSelection(boolean selection) {
            addChangeIdAction.setChecked(selection);
            commitAndPushButton.setImage(getImage(selection ? UIIcons.GERRIT : UIIcons.PUSH));
        }

        @Override
        public void statusUpdated() {
            updateMessage();
        }
    };
    commitMessageComponent = new CommitMessageComponent(listener);
    commitMessageComponent.attachControls(commitMessageText, authorText, committerText);
    // allow to commit with ctrl-enter
    commitMessageText.getTextWidget().addVerifyKeyListener(new VerifyKeyListener() {

        @Override
        public void verifyKey(VerifyEvent event) {
            if (UIUtils.isSubmitKeyEvent(event)) {
                event.doit = false;
                commit(false);
            }
        }
    });
    commitMessageText.getTextWidget().addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            // Ctrl+Enter shortcut only works when the focus is on the commit message text
            String commitButtonTooltip = MessageFormat.format(UIText.StagingView_CommitToolTip, UIUtils.SUBMIT_KEY_STROKE.format());
            commitButton.setToolTipText(commitButtonTooltip);
        }

        @Override
        public void focusLost(FocusEvent e) {
            commitButton.setToolTipText(null);
        }
    });
    // react on selection changes
    IWorkbenchPartSite site = getSite();
    ISelectionService srv = CommonUtils.getService(site, ISelectionService.class);
    srv.addPostSelectionListener(selectionChangedListener);
    CommonUtils.getService(site, IPartService.class).addPartListener(partListener);
    // Use current selection to populate staging view
    UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, site);
    site.setSelectionProvider(new RepositorySelectionProvider(new MultiViewerSelectionProvider(unstagedViewer, stagedViewer), () -> realRepository));
    ViewerFilter filter = new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            StagingViewContentProvider contentProvider = getContentProvider((TreeViewer) viewer);
            if (element instanceof StagingEntry)
                return contentProvider.isInFilter((StagingEntry) element);
            else if (element instanceof StagingFolderEntry)
                return contentProvider.hasVisibleChildren((StagingFolderEntry) element);
            return true;
        }
    };
    unstagedViewer.addFilter(filter);
    stagedViewer.addFilter(filter);
    restoreSashFormWeights();
    reactOnInitialSelection();
    IWorkbenchSiteProgressService service = CommonUtils.getService(getSite(), IWorkbenchSiteProgressService.class);
    if (service != null && reactOnSelection)
        // If we are linked, each time IndexDiffUpdateJob starts, indicate
        // that the view is busy (e.g. reload() will trigger this job in
        // background!).
        service.showBusyForFamily(org.eclipse.egit.core.JobFamilies.INDEX_DIFF_CACHE_UPDATE);
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) RepositoryState(org.eclipse.jgit.lib.RepositoryState) DiffViewer(org.eclipse.egit.ui.internal.commit.DiffViewer) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Cursor(org.eclipse.swt.graphics.Cursor) IEditorPart(org.eclipse.ui.IEditorPart) EnumSet(java.util.EnumSet) Nullable(org.eclipse.jgit.annotations.Nullable) AbortRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.AbortRebaseCommand) JobFamilies(org.eclipse.egit.ui.JobFamilies) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) Constants(org.eclipse.jgit.lib.Constants) Transfer(org.eclipse.swt.dnd.Transfer) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Window(org.eclipse.jface.window.Window) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Path(org.eclipse.core.runtime.Path) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ControlListener(org.eclipse.swt.events.ControlListener) IFileEditorInput(org.eclipse.ui.IFileEditorInput) LinkedHashMap(java.util.LinkedHashMap) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) LaunchFinder(org.eclipse.egit.ui.internal.branch.LaunchFinder) CommitMessageArea(org.eclipse.egit.ui.internal.dialogs.CommitMessageArea) TextTransfer(org.eclipse.swt.dnd.TextTransfer) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) ILabelDecorator(org.eclipse.jface.viewers.ILabelDecorator) Section(org.eclipse.ui.forms.widgets.Section) ControlContribution(org.eclipse.jface.action.ControlContribution) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) IMemento(org.eclipse.ui.IMemento) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) IActionBars(org.eclipse.ui.IActionBars) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Form(org.eclipse.ui.forms.widgets.Form) ICommitMessageComponentNotifications(org.eclipse.egit.ui.internal.dialogs.ICommitMessageComponentNotifications) NoFilepatternException(org.eclipse.jgit.api.errors.NoFilepatternException) UntrackOperation(org.eclipse.egit.core.op.UntrackOperation) ModifyListener(org.eclipse.swt.events.ModifyListener) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IProblemDecoratable(org.eclipse.egit.ui.internal.decorators.IProblemDecoratable) PushMode(org.eclipse.egit.ui.internal.push.PushMode) DisposeListener(org.eclipse.swt.events.DisposeListener) MultiViewerSelectionProvider(org.eclipse.egit.ui.internal.selection.MultiViewerSelectionProvider) IAction(org.eclipse.jface.action.IAction) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) AddCommand(org.eclipse.jgit.api.AddCommand) RuleUtil(org.eclipse.egit.core.internal.job.RuleUtil) IStatus(org.eclipse.core.runtime.IStatus) ISelectionListener(org.eclipse.ui.ISelectionListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) IPartListener2(org.eclipse.ui.IPartListener2) UndoRedoActionGroup(org.eclipse.ui.operations.UndoRedoActionGroup) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ActionUtils(org.eclipse.egit.ui.internal.ActionUtils) Collection(java.util.Collection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AssumeUnchangedOperation(org.eclipse.egit.core.op.AssumeUnchangedOperation) CommitProposalProcessor(org.eclipse.egit.ui.internal.commit.CommitProposalProcessor) GitLabels(org.eclipse.egit.ui.internal.GitLabels) ISelection(org.eclipse.jface.viewers.ISelection) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IShowInTarget(org.eclipse.ui.part.IShowInTarget) UIIcons(org.eclipse.egit.ui.internal.UIIcons) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) OpenEvent(org.eclipse.jface.viewers.OpenEvent) ToggleableWarningLabel(org.eclipse.egit.ui.internal.components.ToggleableWarningLabel) Activator(org.eclipse.egit.ui.Activator) Image(org.eclipse.swt.graphics.Image) MessageFormat(java.text.MessageFormat) CommitOperation(org.eclipse.egit.core.op.CommitOperation) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) HashSet(java.util.HashSet) ContinueRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.ContinueRebaseCommand) IMarker(org.eclipse.core.resources.IMarker) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ContentViewer(org.eclipse.jface.viewers.ContentViewer) Action(org.eclipse.jface.action.Action) IgnoreOperationUI(org.eclipse.egit.ui.internal.operations.IgnoreOperationUI) CheckoutCommand(org.eclipse.jgit.api.CheckoutCommand) Consumer(java.util.function.Consumer) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) ToolBarManager(org.eclipse.jface.action.ToolBarManager) IContributionItem(org.eclipse.jface.action.IContributionItem) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Comparator(java.util.Comparator) SkipRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.SkipRebaseCommand) AdapterUtils(org.eclipse.egit.core.AdapterUtils) UIPreferences(org.eclipse.egit.ui.UIPreferences) DialogSettings(org.eclipse.jface.dialogs.DialogSettings) DND(org.eclipse.swt.dnd.DND) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) FocusEvent(org.eclipse.swt.events.FocusEvent) ReplaceWithOursTheirsMenu(org.eclipse.egit.ui.internal.actions.ReplaceWithOursTheirsMenu) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) ResetCommand(org.eclipse.jgit.api.ResetCommand) Matcher(java.util.regex.Matcher) CommitHelper(org.eclipse.egit.ui.internal.commit.CommitHelper) PartInitException(org.eclipse.ui.PartInitException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Separator(org.eclipse.jface.action.Separator) Text(org.eclipse.swt.widgets.Text) MenuManager(org.eclipse.jface.action.MenuManager) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) DeletePathsOperationUI(org.eclipse.egit.ui.internal.operations.DeletePathsOperationUI) AbstractRebaseCommandHandler(org.eclipse.egit.ui.internal.commands.shared.AbstractRebaseCommandHandler) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) ListenerHandle(org.eclipse.jgit.events.ListenerHandle) CommitMessageComponentState(org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentState) UIText(org.eclipse.egit.ui.internal.UIText) PreferenceChangeEvent(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) JobUtil(org.eclipse.egit.core.internal.job.JobUtil) ActionCommands(org.eclipse.egit.ui.internal.actions.ActionCommands) SWT(org.eclipse.swt.SWT) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) ViewPart(org.eclipse.ui.part.ViewPart) JFaceResources(org.eclipse.jface.resource.JFaceResources) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) IContainer(org.eclipse.core.resources.IContainer) CommitMessageHistory(org.eclipse.egit.ui.internal.commit.CommitMessageHistory) IShowInSource(org.eclipse.ui.part.IShowInSource) ShowInContext(org.eclipse.ui.part.ShowInContext) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) LinkedHashSet(java.util.LinkedHashSet) BaseLabelProvider(org.eclipse.jface.viewers.BaseLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IViewSite(org.eclipse.ui.IViewSite) ExecutionException(org.eclipse.core.commands.ExecutionException) CommonUtils(org.eclipse.egit.ui.internal.CommonUtils) File(java.io.File) IURIEditorInput(org.eclipse.ui.IURIEditorInput) IMenuManager(org.eclipse.jface.action.IMenuManager) ActionFactory(org.eclipse.ui.actions.ActionFactory) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) IPartService(org.eclipse.ui.IPartService) Repository(org.eclipse.jgit.lib.Repository) GridLayout(org.eclipse.swt.layout.GridLayout) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) IndexDiffChangedListener(org.eclipse.egit.core.internal.indexdiff.IndexDiffChangedListener) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) IPath(org.eclipse.core.runtime.IPath) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) CommitMessageComponentStateManager(org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentStateManager) Display(org.eclipse.swt.widgets.Display) IUndoContext(org.eclipse.core.commands.operations.IUndoContext) IHandlerService(org.eclipse.ui.handlers.IHandlerService) List(java.util.List) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) Tree(org.eclipse.swt.widgets.Tree) IFormColors(org.eclipse.ui.forms.IFormColors) CommitJob(org.eclipse.egit.ui.internal.commit.CommitJob) Pattern(java.util.regex.Pattern) IMenuListener(org.eclipse.jface.action.IMenuListener) RmCommand(org.eclipse.jgit.api.RmCommand) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ISelectionService(org.eclipse.ui.ISelectionService) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) CommonUtils.runCommand(org.eclipse.egit.ui.internal.CommonUtils.runCommand) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) FocusListener(org.eclipse.swt.events.FocusListener) VerifyEvent(org.eclipse.swt.events.VerifyEvent) FileTransfer(org.eclipse.swt.dnd.FileTransfer) SpellcheckableMessageArea(org.eclipse.egit.ui.internal.dialogs.SpellcheckableMessageArea) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) Job(org.eclipse.core.runtime.jobs.Job) ProblemLabelDecorator(org.eclipse.egit.ui.internal.decorators.ProblemLabelDecorator) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) TreeItem(org.eclipse.swt.widgets.TreeItem) ObjectId(org.eclipse.jgit.lib.ObjectId) RowLayout(org.eclipse.swt.layout.RowLayout) CommitMessageComponent(org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent) IResource(org.eclipse.core.resources.IResource) GerritUtil(org.eclipse.egit.core.internal.gerrit.GerritUtil) UIUtils(org.eclipse.egit.ui.UIUtils) NonNull(org.eclipse.jgit.annotations.NonNull) Git(org.eclipse.jgit.api.Git) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) Label(org.eclipse.swt.widgets.Label) ToggleableWarningLabel(org.eclipse.egit.ui.internal.components.ToggleableWarningLabel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) CommitProposalProcessor(org.eclipse.egit.ui.internal.commit.CommitProposalProcessor) DiffViewer(org.eclipse.egit.ui.internal.commit.DiffViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ContentViewer(org.eclipse.jface.viewers.ContentViewer) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlListener(org.eclipse.swt.events.ControlListener) ISelectionService(org.eclipse.ui.ISelectionService) MultiViewerSelectionProvider(org.eclipse.egit.ui.internal.selection.MultiViewerSelectionProvider) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ToggleableWarningLabel(org.eclipse.egit.ui.internal.components.ToggleableWarningLabel) ICommitMessageComponentNotifications(org.eclipse.egit.ui.internal.dialogs.ICommitMessageComponentNotifications) IHandlerService(org.eclipse.ui.handlers.IHandlerService) FocusListener(org.eclipse.swt.events.FocusListener) DisposeListener(org.eclipse.swt.events.DisposeListener) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IPartService(org.eclipse.ui.IPartService) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager) ISelection(org.eclipse.jface.viewers.ISelection) VerifyEvent(org.eclipse.swt.events.VerifyEvent) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SashForm(org.eclipse.swt.custom.SashForm) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) ControlEvent(org.eclipse.swt.events.ControlEvent) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CommitMessageComponent(org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent) CommitMessageArea(org.eclipse.egit.ui.internal.dialogs.CommitMessageArea)

Example 47 with ControlListener

use of org.eclipse.swt.events.ControlListener in project eclipse-integration-commons by spring-projects.

the class TableResizeHelper method enableResizing.

public void enableResizing() {
    ControlListener resizeListener = new ControlListener() {

        public void controlResized(ControlEvent e) {
            resizeTable();
        }

        public void controlMoved(ControlEvent e) {
        }
    };
    tableViewer.getTable().addControlListener(resizeListener);
    TableColumn[] cols = tableViewer.getTable().getColumns();
    if (cols != null) {
        for (int i = 0; i < cols.length - 1; i++) {
            cols[i].addControlListener(resizeListener);
        }
    }
    // Initial resize of the columns
    resizeTable();
}
Also used : ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 48 with ControlListener

use of org.eclipse.swt.events.ControlListener in project n4js by eclipse.

the class TestResultsView method createPartControl.

/**
 * This is a callback that will allow us to create the viewer and initialize it.
 */
@Override
public void createPartControl(final Composite parent) {
    GridLayout gl;
    GridData gd;
    gl = new GridLayout(2, false);
    gl.marginWidth = 0;
    gl.marginHeight = 0;
    gl.marginTop = 4;
    parent.setLayout(gl);
    toolBar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = false;
    gd.horizontalAlignment = SWT.CENTER;
    toolBar.setLayoutData(gd);
    progressBar = new TestProgressBar(parent, SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    progressBar.setLayoutData(gd);
    final SashForm sash = new SashForm(parent, SWT.NONE);
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    sash.setLayoutData(gd);
    testTreeViewer = new TreeViewerBuilder(newArrayList("Test", "Status", "Duration"), new TestTreeViewerContentProvider()).setLinesVisible(false).setLabelProvider(new TestTreeViewerLabelProvider()).setColumnWeights(asList(5, 2, 1)).build(sash);
    installToolTipSupport(testTreeViewer.getTree());
    testTreeViewer.setInput(getViewSite());
    stackTrace = new Text(sash, SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    sash.addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            final Point size = parent.getSize();
            final int orientation = size.x > size.y ? SWT.HORIZONTAL : SWT.VERTICAL;
            if (orientation != sash.getOrientation()) {
                sash.setOrientation(orientation);
            }
        }

        @Override
        public void controlMoved(ControlEvent e) {
        // ignore
        }
    });
    createActions();
    hookContextMenu();
    hookDoubleClickAction();
    hookSingleClickAction();
    contributeToActionBars();
    refreshActions();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) TreeViewerBuilder(org.eclipse.n4js.ui.viewer.TreeViewerBuilder) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 49 with ControlListener

use of org.eclipse.swt.events.ControlListener in project balzac by balzac-lang.

the class TrustedNodesPreferences method createNetworkContents.

private void createNetworkContents(Composite parent, boolean testnet) {
    Group group = new Group(parent, SWT.NONE);
    group.setText(testnet ? " Testnet node " : " Mainnet node ");
    GridLayout gl_grpTestnet = new GridLayout(2, false);
    gl_grpTestnet.marginTop = 5;
    gl_grpTestnet.marginRight = 5;
    gl_grpTestnet.marginLeft = 5;
    gl_grpTestnet.marginBottom = 5;
    group.setLayout(gl_grpTestnet);
    Label hostLabel = new Label(group, SWT.NONE);
    hostLabel.setText("Host");
    Text hostText = new Text(group, SWT.BORDER);
    hostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label lblPort = new Label(group, SWT.NONE);
    lblPort.setText("Port");
    Spinner portSpinner = new Spinner(group, SWT.BORDER);
    portSpinner.setMaximum(65535);
    portSpinner.setMinimum(1);
    GridData gd_portSpinner = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_portSpinner.heightHint = 19;
    gd_portSpinner.widthHint = 163;
    portSpinner.setLayoutData(gd_portSpinner);
    Label lblHttpsButton = new Label(group, SWT.NONE);
    lblHttpsButton.setText("Https");
    Button httpsCheckbox = new Button(group, SWT.CHECK);
    httpsCheckbox.setToolTipText("Recommended if the server accepts SSL connections");
    Label usernameLabel = new Label(group, SWT.NONE);
    usernameLabel.setText("Username");
    Text usernameText = new Text(group, SWT.BORDER);
    usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    Label urlLabel = new Label(group, SWT.NONE);
    urlLabel.setText("URL");
    Text urlText = new Text(group, SWT.BORDER);
    urlText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    urlText.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            String text = urlText.getText();
            if (!text.startsWith("/"))
                urlText.setText("/" + text);
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });
    Label testnetPasswordLabel = new Label(group, SWT.NONE);
    testnetPasswordLabel.setText("Password");
    Text passwordText = new Text(group, SWT.BORDER | SWT.PASSWORD);
    passwordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label timeoutLabel = new Label(group, SWT.NONE);
    timeoutLabel.setText("Timeout");
    Spinner timeoutSpinner = new Spinner(group, SWT.BORDER);
    timeoutSpinner.setMaximum(Integer.MAX_VALUE);
    timeoutSpinner.setMinimum(-1);
    timeoutSpinner.setToolTipText("Set -1 for undefined waiting time (not recommended)");
    GridData gd_timeoutSpinner = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_timeoutSpinner.heightHint = 19;
    gd_timeoutSpinner.widthHint = 163;
    timeoutSpinner.setLayoutData(gd_timeoutSpinner);
    // test button with feedbacks
    Composite compositeBtnTest = new Composite(group, SWT.NONE);
    compositeBtnTest.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    GridLayout gl_composite = new GridLayout(2, false);
    gl_composite.horizontalSpacing = 10;
    gl_composite.marginWidth = 0;
    compositeBtnTest.setLayout(gl_composite);
    Button btnTestConnection = new Button(compositeBtnTest, SWT.NONE);
    btnTestConnection.setText("Test");
    Composite compositeFeedbacks = new Composite(compositeBtnTest, SWT.NONE);
    Canvas networkFeedbackOK = new Canvas(compositeFeedbacks, SWT.NONE);
    networkFeedbackOK.setBounds(0, 0, 16, 16);
    networkFeedbackOK.setBackgroundImage(imageSuccess);
    networkFeedbackOK.setVisible(false);
    Canvas networkFeedbackERR = new Canvas(compositeFeedbacks, SWT.NONE);
    networkFeedbackERR.setBounds(0, 0, 16, 16);
    networkFeedbackERR.setBackgroundImage(imageError);
    networkFeedbackERR.setVisible(false);
    // error details
    Composite errorDetailsComposite = new Composite(group, SWT.BORDER);
    StyledText errorDetailsTextArea = new StyledText(errorDetailsComposite, SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);
    GridData gd_errorDetailsTextArea = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
    gd_errorDetailsTextArea.grabExcessVerticalSpace = true;
    errorDetailsComposite.setLayoutData(gd_errorDetailsTextArea);
    errorDetailsComposite.setBackground(errorDetailsTextArea.getBackground());
    errorDetailsTextArea.setAlwaysShowScrollBars(false);
    errorDetailsComposite.addControlListener(new ControlListener() {

        private int TOP_MARGIN = 4;

        private int LEFT_MARGIN = 8;

        @Override
        public void controlResized(ControlEvent e) {
            Composite parent = errorDetailsTextArea.getParent();
            errorDetailsTextArea.setBounds(LEFT_MARGIN, TOP_MARGIN, parent.getSize().x - 2 * parent.getBorderWidth() - LEFT_MARGIN, parent.getSize().y - 2 * parent.getBorderWidth() - TOP_MARGIN);
        }

        @Override
        public void controlMoved(ControlEvent e) {
        }
    });
    btnTestConnection.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            errorDetailsTextArea.setText("");
            networkFeedbackOK.setVisible(false);
            networkFeedbackERR.setVisible(false);
        }

        @Override
        public void mouseUp(MouseEvent e) {
            String address = hostText.getText();
            Integer port = portSpinner.getSelection();
            String protocol = httpsCheckbox.getSelection() ? "https" : "http";
            String url = urlText.getText();
            String user = usernameText.getText();
            String password = passwordText.getText();
            Integer timeout = timeoutSpinner.getSelection();
            if (password.isEmpty()) {
                try {
                    if (testnet)
                        password = secureStorage.node(SecureStorageUtils.SECURE_STORAGE__NODE__BITCOIN__TESTNET_NODE).get(SecureStorageUtils.SECURE_STORAGE__PROPERTY__TESTNET_PASSWORD, "");
                    else
                        password = secureStorage.node(SecureStorageUtils.SECURE_STORAGE__NODE__BITCOIN__MAINNET_NODE).get(SecureStorageUtils.SECURE_STORAGE__PROPERTY__MAINNET_PASSWORD, "");
                } catch (StorageException e1) {
                    e1.printStackTrace();
                    errorDetailsTextArea.append("Error fetching the password from the secure store.\n\n");
                    errorDetailsTextArea.append(Throwables.getStackTraceAsString(e1));
                    networkFeedbackERR.setVisible(true);
                    return;
                }
            }
            RPCBitcoinClient bitcoinClient = new RPCBitcoinClient(address, port, protocol, url, user, password, timeout, TimeUnit.MILLISECONDS);
            try {
                BitcoindApi api = bitcoinClient.getApi();
                boolean isTestnet = api.getblockchaininfo().getChain().equals("test");
                if (isTestnet != testnet) {
                    String expected = testnet ? "testnet" : "mainnet";
                    String actual = isTestnet ? "testnet" : "mainnet";
                    errorDetailsTextArea.append("Wrong network type: expected " + expected + ", found " + actual + ".");
                    networkFeedbackERR.setVisible(true);
                    return;
                }
            } catch (Exception e1) {
                e1.printStackTrace();
                errorDetailsTextArea.append("Cannot connect to the node.\n\n");
                errorDetailsTextArea.append(Throwables.getStackTraceAsString(e1));
                networkFeedbackERR.setVisible(true);
                return;
            }
            errorDetailsTextArea.append("ok");
            networkFeedbackOK.setVisible(true);
        }
    });
    if (testnet)
        testnetHostText = hostText;
    else
        mainnetHostText = hostText;
    if (testnet)
        testnetPortSpinner = portSpinner;
    else
        mainnetPortSpinner = portSpinner;
    if (testnet)
        testnetHttpsCheckbox = httpsCheckbox;
    else
        mainnetHttpsCheckbox = httpsCheckbox;
    if (testnet)
        testnetUrlText = urlText;
    else
        mainnetUrlText = urlText;
    if (testnet)
        testnetUsernameText = usernameText;
    else
        mainnetUsernameText = usernameText;
    if (testnet)
        testnetPasswordText = passwordText;
    else
        mainnetPasswordText = passwordText;
    if (testnet)
        testnetTimeoutSpinner = timeoutSpinner;
    else
        mainnetTimeoutSpinner = timeoutSpinner;
}
Also used : Group(org.eclipse.swt.widgets.Group) StyledText(org.eclipse.swt.custom.StyledText) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) Canvas(org.eclipse.swt.widgets.Canvas) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) RPCBitcoinClient(it.unica.tcs.lib.client.impl.RPCBitcoinClient) FocusEvent(org.eclipse.swt.events.FocusEvent) StorageException(org.eclipse.equinox.security.storage.StorageException) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) FocusListener(org.eclipse.swt.events.FocusListener) StorageException(org.eclipse.equinox.security.storage.StorageException) BitcoindApi(com.sulacosoft.bitcoindconnector4j.BitcoindApi)

Example 50 with ControlListener

use of org.eclipse.swt.events.ControlListener in project selenium_java by sergueik.

the class PreferencesDialog method createCategory.

private Composite createCategory(final TabFolder folder, String category, List<Preference<?>> preferences) {
    final Composite c = new Composite(folder, SWT.NONE);
    c.setLayout(new GridLayout(4, false));
    final List<Label> labels = new ArrayList<Label>();
    org.eclipse.swt.widgets.Group current = null;
    for (final Preference<?> e : preferences) {
        if (e instanceof Group) {
            current = new org.eclipse.swt.widgets.Group(c, SWT.SHADOW_ETCHED_IN);
            current.setText(e.getLabel());
            current.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(4, 1).create());
            current.setLayout(new GridLayout(4, false));
        } else {
            final Label l = new Label(current != null ? current : c, SWT.NONE);
            // $NON-NLS-1$
            l.setText(e.getLabel() + ":");
            labels.add(l);
            editors.put(e, e.getEditor());
            editors.get(e).createControl(current != null ? current : c);
            editors.get(e).setValue(e.getValue());
        }
    }
    // Set equal width on labels
    ControlListener listener = new ControlAdapter() {

        int count = 0;

        int maxWidth = 0;

        @Override
        public void controlResized(ControlEvent arg0) {
            maxWidth = Math.max(((Label) arg0.widget).getSize().x, maxWidth);
            if (++count == labels.size()) {
                GridData gridData = new GridData();
                gridData.widthHint = maxWidth;
                for (Label label : labels) {
                    label.setLayoutData(gridData);
                }
                c.layout(true, true);
            }
        }
    };
    // Attach listener
    for (Label label : labels) {
        label.addControlListener(listener);
    }
    // Return base
    return c;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

ControlEvent (org.eclipse.swt.events.ControlEvent)55 ControlListener (org.eclipse.swt.events.ControlListener)55 GridData (org.eclipse.swt.layout.GridData)21 FocusEvent (org.eclipse.swt.events.FocusEvent)14 Control (org.eclipse.swt.widgets.Control)12 FocusListener (org.eclipse.swt.events.FocusListener)11 MouseEvent (org.eclipse.swt.events.MouseEvent)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 Composite (org.eclipse.swt.widgets.Composite)11 ArrayList (java.util.ArrayList)10 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)10 DisposeEvent (org.eclipse.swt.events.DisposeEvent)10 DisposeListener (org.eclipse.swt.events.DisposeListener)10 Point (org.eclipse.swt.graphics.Point)10 KeyEvent (org.eclipse.swt.events.KeyEvent)9 Event (org.eclipse.swt.widgets.Event)9 Listener (org.eclipse.swt.widgets.Listener)7 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)6 Table (org.eclipse.swt.widgets.Table)6