private void checkPage() { try { upstreamConfigComponent.setUpstreamConfig(upstreamConfig); boolean showUpstreamConfig = sourceRefName.startsWith(Constants.R_HEADS) || sourceRefName.startsWith(Constants.R_REMOTES); Composite container = upstreamConfigComponent.getContainer(); GridData gd = (GridData) container.getLayoutData(); if (gd.exclude == showUpstreamConfig) { gd.exclude = !showUpstreamConfig; container.setVisible(showUpstreamConfig); container.getParent().layout(true); ensurePreferredHeight(getShell()); } boolean basedOnLocalBranch = sourceRefName.startsWith(Constants.R_HEADS); if (basedOnLocalBranch && upstreamConfig != UpstreamConfig.NONE) setMessage(UIText.CreateBranchPage_LocalBranchWarningMessage, IMessageProvider.INFORMATION); if (sourceRefName.length() == 0) { setErrorMessage(UIText.CreateBranchPage_MissingSourceMessage); return; } String message = this.myValidator.isValid(nameText.getText()); if (message != null) { setErrorMessage(message); return; } setErrorMessage(null); } finally { setPageComplete(getErrorMessage() == null && nameText.getText().length() > 0); } }
@Override public void createControl(Composite parent) { Composite main = new Composite(parent, SWT.NONE); main.setLayout(new GridLayout(4, false)); Label sourceLabel = new Label(main, SWT.NONE); sourceLabel.setText(UIText.CreateBranchPage_SourceLabel); sourceLabel.setToolTipText(UIText.CreateBranchPage_SourceTooltip); sourceIcon = new Label(main, SWT.NONE); sourceIcon.setImage(UIIcons.getImage(resourceManager, UIIcons.BRANCH)); sourceIcon.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create()); sourceNameLabel = new Label(main, SWT.NONE); sourceNameLabel.setLayoutData( GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create()); Button selectButton = new Button(main, SWT.NONE); selectButton.setText(UIText.CreateBranchPage_SourceSelectButton); selectButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { selectSource(); } }); UIUtils.setButtonLayoutData(selectButton); Label nameLabel = new Label(main, SWT.NONE); nameLabel.setText(UIText.CreateBranchPage_BranchNameLabel); nameLabel.setLayoutData( GridDataFactory.fillDefaults().span(1, 1).align(SWT.BEGINNING, SWT.CENTER).create()); nameLabel.setToolTipText(UIText.CreateBranchPage_BranchNameToolTip); nameText = new Text(main, SWT.BORDER); // give focus to the nameText if label is activated using the mnemonic nameLabel.addTraverseListener( new TraverseListener() { @Override public void keyTraversed(TraverseEvent e) { nameText.setFocus(); } }); nameText.addModifyListener( new ModifyListener() { @Override public void modifyText(ModifyEvent e) { nameIsSuggestion = false; } }); // enable testing with SWTBot nameText.setData("org.eclipse.swtbot.widget.key", "BranchName"); // $NON-NLS-1$ //$NON-NLS-2$ GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(nameText); upstreamConfigComponent = new UpstreamConfigComponent(main, SWT.NONE); GridDataFactory.fillDefaults() .grab(true, false) .span(4, 1) .applyTo(upstreamConfigComponent.getContainer()); upstreamConfigComponent.addUpstreamConfigSelectionListener( new UpstreamConfigSelectionListener() { @Override public void upstreamConfigSelected(UpstreamConfig newUpstreamConfig) { upstreamConfig = newUpstreamConfig; checkPage(); } }); boolean isBare = myRepository.isBare(); checkout = new Button(main, SWT.CHECK); checkout.setText(UIText.CreateBranchPage_CheckoutButton); // most of the time, we probably will check this out // unless we have a bare repository which doesn't allow // check out at all checkout.setSelection(!isBare); checkout.setEnabled(!isBare); checkout.setVisible(!isBare); GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(checkout); checkout.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); Dialog.applyDialogFont(main); setControl(main); if (this.myBaseCommit != null) setSourceCommit(this.myBaseCommit); else if (myBaseRef != null) setSourceRef(myBaseRef); nameText.setFocus(); // add the listener just now to avoid unneeded checkPage() nameText.addModifyListener( new ModifyListener() { @Override public void modifyText(ModifyEvent e) { checkPage(); } }); }