mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Github: change Task settings layout
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
package org.jetbrains.plugins.github.tasks;
|
||||
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.tasks.config.BaseRepositoryEditor;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.components.JBTextField;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ThrowableConvertor;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import com.intellij.util.ui.GridBag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.github.util.GithubAuthData;
|
||||
@@ -31,25 +31,29 @@ import java.io.IOException;
|
||||
* @author Dennis.Ushakov
|
||||
*/
|
||||
public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepository> {
|
||||
private JTextField myToken;
|
||||
private JTextField myRepoName;
|
||||
private JTextField myRepoAuthor;
|
||||
private MyTextField myHost;
|
||||
private MyTextField myRepoAuthor;
|
||||
private MyTextField myRepoName;
|
||||
private MyTextField myToken;
|
||||
private JButton myTokenButton;
|
||||
private JBLabel myRepoAuthorLabel;
|
||||
private JBLabel myRepoLabel;
|
||||
private JBLabel myHostLabel;
|
||||
private JBLabel myRepositoryLabel;
|
||||
private JBLabel myTokenLabel;
|
||||
|
||||
public GithubRepositoryEditor(final Project project, final GithubRepository repository, Consumer<GithubRepository> changeListener) {
|
||||
super(project, repository, changeListener);
|
||||
myUserNameText.setVisible(false);
|
||||
myUrlLabel.setVisible(false);
|
||||
myURLText.setVisible(false);
|
||||
myUsernameLabel.setVisible(false);
|
||||
myPasswordText.setVisible(false);
|
||||
myUserNameText.setVisible(false);
|
||||
myPasswordLabel.setVisible(false);
|
||||
myPasswordText.setVisible(false);
|
||||
myUseHttpAuthenticationCheckBox.setVisible(false);
|
||||
|
||||
myToken.setText(repository.getToken());
|
||||
myHost.setText(repository.getUrl());
|
||||
myRepoAuthor.setText(repository.getRepoAuthor());
|
||||
myRepoName.setText(repository.getRepoName());
|
||||
myToken.setText(repository.getToken());
|
||||
|
||||
DocumentListener buttonUpdater = new DocumentAdapter() {
|
||||
@Override
|
||||
@@ -58,29 +62,32 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
|
||||
}
|
||||
};
|
||||
|
||||
myHost.getDocument().addDocumentListener(buttonUpdater);
|
||||
myRepoAuthor.getDocument().addDocumentListener(buttonUpdater);
|
||||
myRepoName.getDocument().addDocumentListener(buttonUpdater);
|
||||
myURLText.getDocument().addDocumentListener(buttonUpdater);
|
||||
|
||||
setAnchor(myRepoAuthorLabel);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JComponent createCustomPanel() {
|
||||
myUrlLabel.setText("Host:");
|
||||
myHostLabel = new JBLabel("Host:", SwingConstants.RIGHT);
|
||||
myHost = new MyTextField("Github host");
|
||||
|
||||
myRepoAuthorLabel = new JBLabel("Repository Owner:", SwingConstants.RIGHT);
|
||||
myRepoAuthor = new JTextField();
|
||||
installListener(myRepoAuthor);
|
||||
myRepositoryLabel = new JBLabel("Repository:", SwingConstants.RIGHT);
|
||||
myRepoAuthor = new MyTextField("Repository Owner");
|
||||
myRepoName = new MyTextField("Repository Name");
|
||||
myRepoAuthor.setPreferredSize("SomelongNickname");
|
||||
myRepoName.setPreferredSize("SomelongReponame-with-suffixes");
|
||||
|
||||
myRepoLabel = new JBLabel("Repository:", SwingConstants.RIGHT);
|
||||
myRepoName = new JTextField();
|
||||
installListener(myRepoName);
|
||||
JPanel myRepoPanel = new JPanel(new GridBagLayout());
|
||||
GridBag bag = new GridBag().setDefaultWeightX(1).setDefaultFill(GridBagConstraints.HORIZONTAL);
|
||||
myRepoPanel.add(myRepoAuthor, bag.nextLine().next());
|
||||
myRepoPanel.add(new JLabel("/"), bag.next().fillCellNone().insets(0, 5, 0, 5).weightx(0));
|
||||
myRepoPanel.add(myRepoName, bag.next());
|
||||
|
||||
myTokenLabel = new JBLabel("API Token:", SwingConstants.RIGHT);
|
||||
myToken = new JTextField();
|
||||
installListener(myToken);
|
||||
myToken = new MyTextField("OAuth2 token");
|
||||
myTokenButton = new JButton("Create API token");
|
||||
myTokenButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -94,8 +101,13 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
|
||||
myTokenPanel.add(myToken, BorderLayout.CENTER);
|
||||
myTokenPanel.add(myTokenButton, BorderLayout.EAST);
|
||||
|
||||
return FormBuilder.createFormBuilder().setAlignLabelOnRight(true).addLabeledComponent(myRepoAuthorLabel, myRepoAuthor)
|
||||
.addLabeledComponent(myRepoLabel, myRepoName).addLabeledComponent(myTokenLabel, myTokenPanel).getPanel();
|
||||
installListener(myHost);
|
||||
installListener(myRepoAuthor);
|
||||
installListener(myRepoName);
|
||||
installListener(myToken);
|
||||
|
||||
return FormBuilder.createFormBuilder().setAlignLabelOnRight(true).addLabeledComponent(myHostLabel, myHost)
|
||||
.addLabeledComponent(myRepositoryLabel, myRepoPanel).addLabeledComponent(myTokenLabel, myTokenPanel).getPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,8 +145,8 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
|
||||
@Override
|
||||
public void setAnchor(@Nullable final JComponent anchor) {
|
||||
super.setAnchor(anchor);
|
||||
myRepoAuthorLabel.setAnchor(anchor);
|
||||
myRepoLabel.setAnchor(anchor);
|
||||
myHostLabel.setAnchor(anchor);
|
||||
myRepositoryLabel.setAnchor(anchor);
|
||||
myTokenLabel.setAnchor(anchor);
|
||||
}
|
||||
|
||||
@@ -149,9 +161,14 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myHost;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getHost() {
|
||||
return myURLText.getText().trim();
|
||||
return myHost.getText().trim();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -168,4 +185,25 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
|
||||
private String getToken() {
|
||||
return myToken.getText().trim();
|
||||
}
|
||||
|
||||
public static class MyTextField extends JBTextField {
|
||||
private int myWidth = -1;
|
||||
|
||||
public MyTextField(@NotNull String hintCaption) {
|
||||
getEmptyText().setText(hintCaption);
|
||||
}
|
||||
|
||||
public void setPreferredSize(@NotNull String sampleSizeString) {
|
||||
myWidth = getFontMetrics(getFont()).stringWidth(sampleSizeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension size = super.getPreferredSize();
|
||||
if (myWidth != -1) {
|
||||
size.width = myWidth;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user