use of com.intellij.openapi.ui.LabeledComponent in project intellij-plugins by StepicOrg.
the class StepikPyProjectGenerator method getLocationField.
@Nullable
private TextFieldWithBrowseButton getLocationField() {
if (locationField == null) {
Container basePanel = wizardStep.getComponent().getParent();
if (basePanel == null) {
return null;
}
try {
Container topPanel = (Container) basePanel.getComponent(0);
LabeledComponent locationComponent = (LabeledComponent) topPanel.getComponent(0);
locationField = (TextFieldWithBrowseButton) locationComponent.getComponent();
} catch (ClassCastException | ArrayIndexOutOfBoundsException e) {
logger.warn("Auto naming for a project don't work: ", e);
return null;
}
}
return locationField;
}
use of com.intellij.openapi.ui.LabeledComponent in project intellij-community by JetBrains.
the class GenerateVisitorByHierarchyAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
final Ref<String> visitorNameRef = Ref.create("MyVisitor");
final Ref<PsiClass> parentClassRef = Ref.create(null);
final Project project = e.getData(CommonDataKeys.PROJECT);
assert project != null;
final PsiNameHelper helper = PsiNameHelper.getInstance(project);
final PackageChooserDialog dialog = new PackageChooserDialog("Choose Target Package and Hierarchy Root Class", project) {
@Override
protected ValidationInfo doValidate() {
PsiDocumentManager.getInstance(project).commitAllDocuments();
if (!helper.isQualifiedName(visitorNameRef.get())) {
return new ValidationInfo("Visitor class name is not valid");
} else if (parentClassRef.isNull()) {
return new ValidationInfo("Hierarchy root class should be specified");
} else if (parentClassRef.get().isAnnotationType() || parentClassRef.get().isEnum()) {
return new ValidationInfo("Hierarchy root class should be an interface or a class");
}
return super.doValidate();
}
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new BorderLayout());
panel.add(super.createCenterPanel(), BorderLayout.CENTER);
panel.add(createNamePanel(), BorderLayout.NORTH);
panel.add(createBaseClassPanel(), BorderLayout.SOUTH);
return panel;
}
private JComponent createNamePanel() {
LabeledComponent<JTextField> labeledComponent = new LabeledComponent<>();
labeledComponent.setText("Visitor class");
final JTextField nameField = new JTextField(visitorNameRef.get());
labeledComponent.setComponent(nameField);
nameField.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
visitorNameRef.set(nameField.getText());
}
});
return labeledComponent;
}
private JComponent createBaseClassPanel() {
LabeledComponent<EditorTextField> labeledComponent = new LabeledComponent<>();
labeledComponent.setText("Hierarchy root class");
final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
final PsiTypeCodeFragment codeFragment = factory.createTypeCodeFragment("", null, true, JavaCodeFragmentFactory.ALLOW_VOID);
final Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
final EditorTextField editorTextField = new EditorTextField(document, project, StdFileTypes.JAVA);
labeledComponent.setComponent(editorTextField);
editorTextField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
public void documentChanged(final com.intellij.openapi.editor.event.DocumentEvent e) {
parentClassRef.set(null);
try {
final PsiType psiType = codeFragment.getType();
final PsiClass psiClass = psiType instanceof PsiClassType ? ((PsiClassType) psiType).resolve() : null;
parentClassRef.set(psiClass);
} catch (PsiTypeCodeFragment.IncorrectTypeException e1) {
// ok
}
}
});
return labeledComponent;
}
};
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(e.getDataContext());
if (element instanceof PsiPackage) {
dialog.selectPackage(((PsiPackage) element).getQualifiedName());
} else if (element instanceof PsiDirectory) {
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
if (aPackage != null) {
dialog.selectPackage(aPackage.getQualifiedName());
}
}
dialog.show();
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE || dialog.getSelectedPackage() == null || dialog.getSelectedPackage().getQualifiedName().length() == 0 || parentClassRef.isNull()) {
return;
}
final String visitorQName = generateEverything(dialog.getSelectedPackage(), parentClassRef.get(), visitorNameRef.get());
final IdeView ideView = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorQName, GlobalSearchScope.projectScope(project));
if (ideView != null && visitorClass != null) {
ideView.selectElement(visitorClass);
}
}
use of com.intellij.openapi.ui.LabeledComponent in project intellij-community by JetBrains.
the class ConfigurationsTest method testEditJUnitConfiguration.
public void testEditJUnitConfiguration() throws ConfigurationException {
if (PlatformTestUtil.COVERAGE_ENABLED_BUILD)
return;
PsiClass testA = findTestA(getModule2());
JUnitConfiguration configuration = createConfiguration(testA);
JUnitConfigurable editor = new JUnitConfigurable(myProject);
try {
Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration);
configurable.reset();
final EditorTextFieldWithBrowseButton component = ((LabeledComponent<EditorTextFieldWithBrowseButton>) editor.getTestLocation(JUnitConfigurationModel.CLASS)).getComponent();
assertEquals(testA.getQualifiedName(), component.getText());
PsiClass otherTest = findClass(getModule2(), "test2.Test2");
component.setText(otherTest.getQualifiedName());
configurable.apply();
assertEquals(otherTest.getName(), configuration.getName());
String specialName = "My name";
configuration.setName(specialName);
configuration.setNameChangedByUser(true);
configurable.reset();
component.setText(testA.getQualifiedName());
configurable.apply();
assertEquals(specialName, configuration.getName());
} finally {
Disposer.dispose(editor);
}
}
use of com.intellij.openapi.ui.LabeledComponent in project intellij-community by JetBrains.
the class MergePanel2 method setDiffRequest.
public void setDiffRequest(DiffRequest data) {
setTitle(data.getWindowTitle());
disposeMergeList();
for (int i = 0; i < EDITORS_COUNT; i++) {
getEditorPlace(i).setDocument(null);
}
LOG.assertTrue(!myDuringCreation);
myDuringCreation = true;
myProvider.putData(data.getGenericData());
try {
myData = data;
String[] titles = myData.getContentTitles();
for (int i = 0; i < myEditorsPanels.length; i++) {
LabeledComponent editorsPanel = myEditorsPanels[i];
editorsPanel.getLabel().setText(titles[i].isEmpty() ? " " : titles[i]);
}
createMergeList();
data.customizeToolbar(myPanel.resetToolbar());
myPanel.registerToolbarActions();
if (data instanceof MergeRequestImpl && myBuilder != null) {
Convertor<DialogWrapper, Boolean> preOkHook = new Convertor<DialogWrapper, Boolean>() {
@Override
public Boolean convert(DialogWrapper dialog) {
ChangeCounter counter = ChangeCounter.getOrCreate(myMergeList);
int changes = counter.getChangeCounter();
int conflicts = counter.getConflictCounter();
if (changes == 0 && conflicts == 0)
return true;
return Messages.showYesNoDialog(dialog.getRootPane(), DiffBundle.message("merge.dialog.apply.partially.resolved.changes.confirmation.message", changes, conflicts), DiffBundle.message("apply.partially.resolved.merge.dialog.title"), Messages.getQuestionIcon()) == Messages.YES;
}
};
((MergeRequestImpl) data).setActions(myBuilder, this, preOkHook);
}
} finally {
myDuringCreation = false;
}
}
use of com.intellij.openapi.ui.LabeledComponent in project intellij-community by JetBrains.
the class ProjectSettingsPanel method getMainComponent.
public JComponent getMainComponent() {
final LabeledComponent<JComboBox> component = new LabeledComponent<>();
component.setText("Default &project copyright:");
component.setLabelLocation(BorderLayout.WEST);
component.setComponent(myProfilesComboBox);
ElementProducer<ScopeSetting> producer = new ElementProducer<ScopeSetting>() {
@Override
public ScopeSetting createElement() {
return new ScopeSetting(CustomScopesProviderEx.getAllScope(), myProfilesModel.getAllProfiles().values().iterator().next());
}
@Override
public boolean canCreateElement() {
return !myProfilesModel.getAllProfiles().isEmpty();
}
};
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myScopeMappingTable, producer);
return JBUI.Panels.simplePanel(0, 10).addToTop(component).addToCenter(decorator.createPanel()).addToBottom(myScopesLink);
}
Aggregations