use of com.intellij.ui.HideableDecorator in project android by JetBrains.
the class TreeGrid method setModel.
private void setModel(@NotNull AbstractTreeStructure model, boolean showSectionHeaders) {
// using the AbstractTreeStructure instead of the model as the actual TreeModel when used with IJ components
// works in a very strange way, each time you expand or contract a node it will add or remove all its children.
Object root = model.getRootElement();
Object[] sections = model.getChildElements(root);
mySectionToComponent.clear();
myLists.clear();
myHideables.clear();
removeAll();
setAutoscrolls(false);
ListSelectionListener listSelectionListener = e -> {
if (e.getValueIsAdjusting()) {
return;
}
ListSelectionModel sourceSelectionModel = (ListSelectionModel) e.getSource();
if (!sourceSelectionModel.isSelectionEmpty()) {
for (JList<T> aList : myLists) {
if (sourceSelectionModel != aList.getSelectionModel()) {
aList.clearSelection();
}
}
}
};
for (Object section : sections) {
String name = section.toString();
FilteringListModel<T> listModel = new FilteringListModel<>(new AbstractListModel() {
@Override
public int getSize() {
return model.getChildElements(section).length;
}
@Override
public Object getElementAt(int index) {
return model.getChildElements(section)[index];
}
});
// Needed as otherwise the filtered list does not show any content.
listModel.refilter();
// JBList does not work with HORIZONTAL_WRAP
//noinspection UndesirableClassUsage,unchecked
JList<T> list = new JList<>(listModel);
list.setAutoscrolls(false);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(-1);
list.getSelectionModel().addListSelectionListener(listSelectionListener);
// for tests to find the right list
list.setName(name);
list.addKeyListener(myKeyListener);
new ListSpeedSearch(list);
myLists.add(list);
if (showSectionHeaders) {
JPanel panel = new // must be BorderLayout for HideableDecorator to work
JPanel(// must be BorderLayout for HideableDecorator to work
new BorderLayout()) {
@Override
public Dimension getMaximumSize() {
return new Dimension(super.getMaximumSize().width, super.getPreferredSize().height);
}
};
HideableDecorator hidyPanel = new HideableDecorator(panel, name, false);
myHideables.add(hidyPanel);
hidyPanel.setContentComponent(list);
add(panel);
mySectionToComponent.put(section, panel);
} else {
if (getComponentCount() > 0) {
add(new JSeparator());
}
list.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
add(list);
mySectionToComponent.put(section, list);
}
}
}
use of com.intellij.ui.HideableDecorator in project azure-tools-for-java by Microsoft.
the class IntellijErrorDialog method init.
@Override
protected void init() {
super.init();
this.iconLabel.setIcon(Messages.getErrorIcon());
this.contentPane.setText(message.getContent());
this.contentPane.setBackground(JBColor.WHITE);
this.contentPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
this.contentPane.addHyperlinkListener(e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
BrowserUtil.browse(e.getURL());
}
});
final String details = message.getDetails();
if (StringUtils.isNotBlank(details)) {
final HideableDecorator slotDecorator = new HideableDecorator(detailsContainer, "&Call Stack", false);
slotDecorator.setContentComponent(detailsScrollPane);
slotDecorator.setOn(false);
this.detailsPane.setText(details);
this.detailsPane.setBackground(JBColor.WHITE);
this.detailsPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
} else {
this.detailsContainer.setVisible(false);
}
}
use of com.intellij.ui.HideableDecorator in project intellij-community by JetBrains.
the class ProjectSpecificSettingsStep method createAdvancedSettings.
@Override
@Nullable
protected JPanel createAdvancedSettings() {
JComponent advancedSettings = null;
if (myProjectGenerator instanceof PythonProjectGenerator) {
advancedSettings = ((PythonProjectGenerator) myProjectGenerator).getSettingsPanel(myProjectDirectory);
} else if (myProjectGenerator instanceof WebProjectTemplate) {
advancedSettings = ((WebProjectTemplate) myProjectGenerator).getPeer().getComponent();
}
if (advancedSettings != null) {
final JPanel jPanel = new JPanel(new VerticalFlowLayout());
final HideableDecorator deco = new HideableDecorator(jPanel, "Mor&e Settings", false);
boolean isValid = checkValid();
deco.setOn(!isValid);
if (myProjectGenerator instanceof PythonProjectGenerator && !deco.isExpanded()) {
final ValidationResult result = ((PythonProjectGenerator) myProjectGenerator).warningValidation(getSdk());
deco.setOn(!result.isOk());
}
deco.setContentComponent(advancedSettings);
return jPanel;
}
return null;
}
use of com.intellij.ui.HideableDecorator in project ballerina by ballerina-lang.
the class BallerinaLibrariesConfigurableProvider method createConfigurable.
@Nullable
private Configurable createConfigurable(boolean dialogMode) {
return new CompositeConfigurable<UnnamedConfigurable>() {
@Nullable
@Override
public JComponent createComponent() {
List<UnnamedConfigurable> configurables = getConfigurables();
Collection<HideableDecorator> hideableDecorators = ContainerUtil.newHashSet();
GridLayoutManager layoutManager = new GridLayoutManager(configurables.size() + 1, 1, new Insets(0, 0, 0, 0), -1, -1);
JPanel rootPanel = new JPanel(layoutManager);
Spacer spacer = new Spacer();
rootPanel.add(spacer, new GridConstraints(configurables.size(), 0, 1, 1, GridConstraints.ANCHOR_SOUTH, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
for (int i = 0; i < configurables.size(); i++) {
UnnamedConfigurable configurable = configurables.get(i);
JComponent configurableComponent = configurable.createComponent();
assert configurableComponent != null;
JPanel hideablePanel = new JPanel(new BorderLayout());
rootPanel.add(hideablePanel, configurableConstrains(i));
if (configurable instanceof Configurable) {
String displayName = ((Configurable) configurable).getDisplayName();
ListenableHideableDecorator decorator = new ListenableHideableDecorator(hideablePanel, displayName, configurableComponent);
decorator.addListener(new MyHideableDecoratorListener(layoutManager, hideablePanel, spacer, hideableDecorators, configurableExpandedPropertyKey((Configurable) configurable)));
hideableDecorators.add(decorator);
decorator.setOn(isConfigurableExpanded(i, (Configurable) configurable));
}
}
if (dialogMode) {
rootPanel.setPreferredSize(new Dimension(400, 600));
}
rootPanel.revalidate();
return rootPanel;
}
@NotNull
@Override
protected List<UnnamedConfigurable> createConfigurables() {
List<UnnamedConfigurable> result = ContainerUtil.newArrayList();
String[] urlsFromEnv = ContainerUtil.map2Array(BallerinaSdkUtil.getBallerinaPathsRootsFromEnvironment(), String.class, VirtualFile::getUrl);
result.add(new BallerinaLibrariesConfigurable("Global libraries", BallerinaApplicationLibrariesService.getInstance(), urlsFromEnv));
if (!myProject.isDefault()) {
result.add(new BallerinaLibrariesConfigurable("Project libraries", BallerinaProjectLibrariesService.getInstance(myProject)));
}
return result;
}
@NotNull
@Nls
@Override
public String getDisplayName() {
return "Ballerina Libraries";
}
@Nullable
@Override
public String getHelpTopic() {
return null;
}
@NotNull
private GridConstraints configurableConstrains(int i) {
return new GridConstraints(i, 0, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null);
}
private boolean isConfigurableExpanded(int index, @NotNull Configurable configurable) {
return PropertiesComponent.getInstance(myProject).getBoolean(configurableExpandedPropertyKey(configurable), index < 2);
}
private void storeConfigurableExpandedProperty(@NotNull String storeKey, @NotNull Boolean value) {
PropertiesComponent.getInstance(myProject).setValue(storeKey, value.toString());
}
private String configurableExpandedPropertyKey(@NotNull Configurable configurable) {
String keyName = "configurable " + configurable.getDisplayName() + " is expanded".toLowerCase(Locale.US);
return StringUtil.replaceChar(keyName, ' ', '.');
}
class MyHideableDecoratorListener extends ListenableHideableDecorator.MyListener {
private final GridLayoutManager myLayoutManager;
private final JPanel myHideablePanel;
@NotNull
private final String myStoreKey;
private final Spacer mySpacer;
private final Collection<HideableDecorator> myHideableDecorators;
public MyHideableDecoratorListener(@NotNull GridLayoutManager layoutManager, @NotNull JPanel hideablePanel, @NotNull Spacer spacer, @NotNull Collection<HideableDecorator> hideableDecorators, @NotNull String storeKey) {
myLayoutManager = layoutManager;
myHideablePanel = hideablePanel;
myStoreKey = storeKey;
mySpacer = spacer;
myHideableDecorators = hideableDecorators;
}
@Override
public void on() {
GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
GridConstraints spacerConstraints = myLayoutManager.getConstraintsForComponent(mySpacer);
spacerConstraints.setVSizePolicy(spacerConstraints.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
storeConfigurableExpandedProperty(myStoreKey, Boolean.TRUE);
}
@Override
public void beforeOff() {
GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
c.setVSizePolicy(c.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
}
@Override
public void afterOff() {
if (isAllDecoratorsCollapsed()) {
GridConstraints c = myLayoutManager.getConstraintsForComponent(mySpacer);
c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
}
storeConfigurableExpandedProperty(myStoreKey, Boolean.FALSE);
}
private boolean isAllDecoratorsCollapsed() {
for (HideableDecorator hideableDecorator : myHideableDecorators) {
if (hideableDecorator.isExpanded()) {
return false;
}
}
return true;
}
}
};
}
use of com.intellij.ui.HideableDecorator in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoLibrariesConfigurableProvider method createConfigurable.
@Nullable
private Configurable createConfigurable(boolean dialogMode) {
return new CompositeConfigurable<UnnamedConfigurable>() {
@Nullable
@Override
public JComponent createComponent() {
List<UnnamedConfigurable> configurables = getConfigurables();
Collection<HideableDecorator> hideableDecorators = ContainerUtil.newHashSet();
GridLayoutManager layoutManager = new GridLayoutManager(configurables.size() + 1, 1, new Insets(0, 0, 0, 0), -1, -1);
JPanel rootPanel = new JPanel(layoutManager);
Spacer spacer = new Spacer();
rootPanel.add(spacer, new GridConstraints(configurables.size(), 0, 1, 1, GridConstraints.ANCHOR_SOUTH, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
for (int i = 0; i < configurables.size(); i++) {
UnnamedConfigurable configurable = configurables.get(i);
JComponent configurableComponent = configurable.createComponent();
assert configurableComponent != null;
JPanel hideablePanel = new JPanel(new BorderLayout());
rootPanel.add(hideablePanel, configurableConstrains(i));
if (configurable instanceof Configurable) {
String displayName = ((Configurable) configurable).getDisplayName();
ListenableHideableDecorator decorator = new ListenableHideableDecorator(hideablePanel, displayName, configurableComponent);
decorator.addListener(new MyHideableDecoratorListener(layoutManager, hideablePanel, spacer, hideableDecorators, configurableExpandedPropertyKey((Configurable) configurable)));
hideableDecorators.add(decorator);
decorator.setOn(isConfigurableExpanded(i, (Configurable) configurable));
}
}
if (dialogMode) {
rootPanel.setPreferredSize(new Dimension(400, 600));
}
rootPanel.revalidate();
return rootPanel;
}
@NotNull
@Override
protected List<UnnamedConfigurable> createConfigurables() {
List<UnnamedConfigurable> result = ContainerUtil.newArrayList();
String[] urlsFromEnv = ContainerUtil.map2Array(GoSdkUtil.getGoPathsRootsFromEnvironment(), String.class, VirtualFile::getUrl);
result.add(new GoLibrariesConfigurable("Global libraries", GoApplicationLibrariesService.getInstance(), urlsFromEnv));
if (!myProject.isDefault()) {
result.add(new GoLibrariesConfigurable("Project libraries", GoProjectLibrariesService.getInstance(myProject)));
result.add(new GoModuleAwareConfigurable(myProject, "Module libraries", null) {
@NotNull
@Override
protected UnnamedConfigurable createModuleConfigurable(@NotNull Module module) {
return new GoLibrariesConfigurable("Module libraries", GoModuleLibrariesService.getInstance(module));
}
});
}
return result;
}
@NotNull
@Nls
@Override
public String getDisplayName() {
return "Go Libraries";
}
@Nullable
@Override
public String getHelpTopic() {
return null;
}
@NotNull
private GridConstraints configurableConstrains(int i) {
return new GridConstraints(i, 0, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null);
}
private boolean isConfigurableExpanded(int index, @NotNull Configurable configurable) {
return PropertiesComponent.getInstance(myProject).getBoolean(configurableExpandedPropertyKey(configurable), index < 2);
}
private void storeConfigurableExpandedProperty(@NotNull String storeKey, @NotNull Boolean value) {
PropertiesComponent.getInstance(myProject).setValue(storeKey, value.toString());
}
private String configurableExpandedPropertyKey(@NotNull Configurable configurable) {
String keyName = "configurable " + configurable.getDisplayName() + " is expanded".toLowerCase(Locale.US);
return StringUtil.replaceChar(keyName, ' ', '.');
}
class MyHideableDecoratorListener extends ListenableHideableDecorator.MyListener {
private final GridLayoutManager myLayoutManager;
private final JPanel myHideablePanel;
@NotNull
private final String myStoreKey;
private final Spacer mySpacer;
private final Collection<HideableDecorator> myHideableDecorators;
public MyHideableDecoratorListener(@NotNull GridLayoutManager layoutManager, @NotNull JPanel hideablePanel, @NotNull Spacer spacer, @NotNull Collection<HideableDecorator> hideableDecorators, @NotNull String storeKey) {
myLayoutManager = layoutManager;
myHideablePanel = hideablePanel;
myStoreKey = storeKey;
mySpacer = spacer;
myHideableDecorators = hideableDecorators;
}
@Override
public void on() {
GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
GridConstraints spacerConstraints = myLayoutManager.getConstraintsForComponent(mySpacer);
spacerConstraints.setVSizePolicy(spacerConstraints.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
storeConfigurableExpandedProperty(myStoreKey, Boolean.TRUE);
}
@Override
public void beforeOff() {
GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
c.setVSizePolicy(c.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
}
@Override
public void afterOff() {
if (isAllDecoratorsCollapsed()) {
GridConstraints c = myLayoutManager.getConstraintsForComponent(mySpacer);
c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
}
storeConfigurableExpandedProperty(myStoreKey, Boolean.FALSE);
}
private boolean isAllDecoratorsCollapsed() {
for (HideableDecorator hideableDecorator : myHideableDecorators) {
if (hideableDecorator.isExpanded()) {
return false;
}
}
return true;
}
}
};
}
Aggregations