use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.
the class DomUIFactory method createCollectionControl.
public DomUIControl createCollectionControl(DomElement element, DomCollectionChildDescription description) {
final ColumnInfo columnInfo = createColumnInfo(description, element);
final Class aClass = DomUtil.extractParameterClassFromGenericType(description.getType());
return new DomCollectionControl<>(element, description, aClass == null, columnInfo);
}
use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.
the class DynamicToolWindowWrapper method createTable.
private JScrollPane createTable(final MutableTreeNode myTreeRoot) {
ColumnInfo[] columnInfos = { new ClassColumnInfo(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]), new PropertyTypeColumnInfo(myColumnNames[TYPE_COLUMN]) };
myTreeTableModel = new ListTreeTableModelOnColumns(myTreeRoot, columnInfos);
myTreeTable = new MyTreeTable(myTreeTableModel);
new TreeTableSpeedSearch(myTreeTable, new Convertor<TreePath, String>() {
@Override
public String convert(TreePath o) {
final Object node = o.getLastPathComponent();
if (node instanceof DefaultMutableTreeNode) {
final Object object = ((DefaultMutableTreeNode) node).getUserObject();
if (object instanceof DNamedElement) {
return ((DNamedElement) object).getName();
}
}
return "";
}
});
DefaultActionGroup group = new DefaultActionGroup();
group.add(ActionManager.getInstance().getAction(RemoveDynamicAction.GROOVY_DYNAMIC_REMOVE));
PopupHandler.installUnknownPopupHandler(myTreeTable, group, ActionManager.getInstance());
final MyColoredTreeCellRenderer treeCellRenderer = new MyColoredTreeCellRenderer();
myTreeTable.setDefaultRenderer(String.class, new TableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value instanceof String) {
try {
final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText((String) value, null);
String shortName = type.getPresentableText();
return new JLabel(shortName);
} catch (IncorrectOperationException e) {
LOG.debug("Type cannot be created", e);
}
return new JLabel(QuickfixUtil.shortenType((String) value));
}
return new JLabel();
}
});
myTreeTable.setTreeCellRenderer(treeCellRenderer);
myTreeTable.setRootVisible(false);
myTreeTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
final MyPropertyTypeCellEditor typeCellEditor = new MyPropertyTypeCellEditor();
typeCellEditor.addCellEditorListener(new CellEditorListener() {
@Override
public void editingStopped(ChangeEvent e) {
final TreeTableTree tree = getTree();
String newTypeValue = ((MyPropertyTypeCellEditor) e.getSource()).getCellEditorValue();
if (newTypeValue == null || tree == null) {
myTreeTable.editingStopped(e);
return;
}
try {
final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText(newTypeValue, null);
String canonical = type.getCanonicalText();
if (canonical != null)
newTypeValue = canonical;
} catch (IncorrectOperationException ex) {
//do nothing in case bad string is entered
}
final TreePath editingTypePath = tree.getSelectionPath();
if (editingTypePath == null)
return;
final TreePath editingClassPath = editingTypePath.getParentPath();
Object oldTypeValue = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), TYPE_COLUMN);
if (!(oldTypeValue instanceof String)) {
myTreeTable.editingStopped(e);
return;
}
final Object editingPropertyObject = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), CLASS_OR_ELEMENT_NAME_COLUMN);
final Object editingClassObject = myTreeTable.getValueAt(tree.getRowForPath(editingClassPath), CLASS_OR_ELEMENT_NAME_COLUMN);
if (!(editingPropertyObject instanceof DItemElement) || !(editingClassObject instanceof DClassElement)) {
myTreeTable.editingStopped(e);
return;
}
final DItemElement dynamicElement = (DItemElement) editingPropertyObject;
final String name = dynamicElement.getName();
final String className = ((DClassElement) editingClassObject).getName();
if (dynamicElement instanceof DPropertyElement) {
DynamicManager.getInstance(myProject).replaceDynamicPropertyType(className, name, (String) oldTypeValue, newTypeValue);
} else if (dynamicElement instanceof DMethodElement) {
final List<ParamInfo> myPairList = ((DMethodElement) dynamicElement).getPairs();
DynamicManager.getInstance(myProject).replaceDynamicMethodType(className, name, myPairList, (String) oldTypeValue, newTypeValue);
}
}
@Override
public void editingCanceled(ChangeEvent e) {
myTreeTable.editingCanceled(e);
}
});
RefactoringListenerManager.getInstance(myProject).addListenerProvider(new RefactoringElementListenerProvider() {
@Override
@Nullable
public RefactoringElementListener getListener(final PsiElement element) {
if (element instanceof PsiClass) {
final String qualifiedName = ((PsiClass) element).getQualifiedName();
return new RefactoringElementListener() {
@Override
public void elementMoved(@NotNull PsiElement newElement) {
renameElement(qualifiedName, newElement);
}
@Override
public void elementRenamed(@NotNull PsiElement newElement) {
renameElement(qualifiedName, newElement);
}
private void renameElement(String oldClassName, PsiElement newElement) {
if (newElement instanceof PsiClass) {
final String newClassName = ((PsiClass) newElement).getQualifiedName();
final DRootElement rootElement = DynamicManager.getInstance(myProject).getRootElement();
final DClassElement oldClassElement = rootElement.getClassElement(oldClassName);
final TreeNode oldClassNode = TreeUtil.findNodeWithObject((DefaultMutableTreeNode) myTreeRoot, oldClassElement);
DynamicManager.getInstance(myProject).replaceClassName(oldClassElement, newClassName);
myTreeTableModel.nodeChanged(oldClassNode);
}
}
};
}
return null;
}
});
myTreeTable.setDefaultEditor(String.class, typeCellEditor);
myTreeTable.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
myTreeTable.editCellAt(selectionRow, CLASS_OR_ELEMENT_NAME_COLUMN, event);
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), JComponent.WHEN_FOCUSED);
myTreeTable.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
myTreeTable.editCellAt(selectionRow, TYPE_COLUMN, event);
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
myTreeTable.getTree().setShowsRootHandles(true);
myTreeTable.getTableHeader().setReorderingAllowed(false);
myTreeTable.setPreferredScrollableViewportSize(new Dimension(300, myTreeTable.getRowHeight() * 10));
myTreeTable.getColumn(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]).setPreferredWidth(200);
myTreeTable.getColumn(myColumnNames[TYPE_COLUMN]).setPreferredWidth(160);
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTreeTable);
scrollPane.setPreferredSize(JBUI.size(600, 400));
return scrollPane;
}
use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.
the class SvnHistoryProvider method getUICustomization.
@Override
public VcsDependentHistoryComponents getUICustomization(final VcsHistorySession session, JComponent forShortcutRegistration) {
final ColumnInfo[] columns;
final Consumer<VcsFileRevision> listener;
final JComponent addComp;
if (((SvnHistorySession) session).isHaveMergeSources()) {
final MergeSourceColumnInfo mergeSourceColumn = new MergeSourceColumnInfo((SvnHistorySession) session);
columns = new ColumnInfo[] { new CopyFromColumnInfo(), mergeSourceColumn };
final JTextArea field = new JTextArea() {
final StatusText statusText = new StatusText(this) {
@Override
protected boolean isStatusVisible() {
return getDocument().getLength() == 0;
}
};
@Override
public Color getBackground() {
return UIUtil.getEditorPaneBackground();
}
{
statusText.setText("Merge sources");
setWrapStyleWord(true);
setLineWrap(true);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
statusText.paint(this, g);
}
};
field.setEditable(false);
field.setOpaque(false);
field.setWrapStyleWord(true);
listener = vcsFileRevision -> {
field.setText(mergeSourceColumn.getText(vcsFileRevision));
field.setCaretPosition(0);
field.repaint();
};
final MergeSourceDetailsAction sourceAction = new MergeSourceDetailsAction();
sourceAction.registerSelf(forShortcutRegistration);
JPanel fieldPanel = new ToolbarDecorator() {
@Override
protected JComponent getComponent() {
return field;
}
@Override
protected void updateButtons() {
}
@Override
protected void installDnDSupport() {
}
@Override
protected boolean isModelEditable() {
return false;
}
}.initPosition().addExtraAction(AnActionButton.fromAction(sourceAction)).createPanel();
fieldPanel.setBorder(IdeBorderFactory.createEmptyBorder());
addComp = fieldPanel;
} else {
columns = new ColumnInfo[] { new CopyFromColumnInfo() };
addComp = null;
listener = null;
}
return new VcsDependentHistoryComponents(columns, listener, addComp);
}
use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.
the class ExtractedSettingsDialog method buildExtractedSettingsTree.
protected JComponent buildExtractedSettingsTree() {
Collection<Value> unusedValues = ContainerUtil.newHashSet(myValues);
myRoot = new DefaultMutableTreeNode();
for (Map.Entry<LanguageCodeStyleSettingsProvider.SettingsType, Map<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>>> typeEntry : myNameProvider.mySettings.entrySet()) {
DefaultMutableTreeNode settingsNode = null;
for (Map.Entry<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>> groupEntry : typeEntry.getValue().entrySet()) {
CodeStyleSettingPresentation.SettingsGroup group = groupEntry.getKey();
List<CodeStyleSettingPresentation> representations = groupEntry.getValue();
List<CodeStyleSettingPresentation> children = ContainerUtil.emptyList();
DefaultMutableTreeNode groupNode = null;
if (group.name == null && !representations.isEmpty()) {
//there is a setting with name coinciding with group name
if (representations.size() > 1) {
children = representations.subList(1, representations.size());
}
CodeStyleSettingPresentation headRep = representations.get(0);
Value myValue = CodeStyleSettingsNameProvider.getValue(headRep, myValues);
if (myValue == null) {
//value was not found (was not selected)
groupNode = new SettingsTreeNode(headRep.getUiName());
} else {
groupNode = new SettingsTreeNode(headRep.getUiName());
groupNode.add(new SettingsTreeNode(headRep.getValueUiName(myValue.value), headRep, true, myValue));
unusedValues.remove(myValue);
}
} else {
children = representations;
}
for (CodeStyleSettingPresentation representation : children) {
Value myValue = CodeStyleSettingsNameProvider.getValue(representation, myValues);
if (myValue != null) {
if (groupNode == null) {
groupNode = new SettingsTreeNode(group.name);
}
groupNode.add(new SettingsTreeNode(representation.getValueUiName(myValue.value), representation, false, myValue));
unusedValues.remove(myValue);
}
}
if (groupNode != null && !groupNode.isLeaf()) {
if (settingsNode == null) {
settingsNode = new SettingsTreeNode(CodeStyleSettingsNameProvider.getSettingsTypeName(typeEntry.getKey()));
}
settingsNode.add(groupNode);
}
}
if (settingsNode != null) {
myRoot.add(settingsNode);
}
}
//TODO: for now, settings without UI presentation are not displayed. Do something about it.
//unusedValues = ContainerUtil.filter(unusedValues, new Condition<Value>(){
// @Override
// public boolean value(Value value) {
// return value.state == Value.STATE.SELECTED;
// }
//});
//
//DefaultMutableTreeNode unnamedNode = null;
//for (Value value: unusedValues) {
// if (unnamedNode == null) {
// unnamedNode = new SettingsTreeNode("Settings without UI representation");
// }
// unnamedNode.add(new SettingsTreeNode(value.value.toString(), null, false, value.name, value));
//}
//
//if (unnamedNode != null) {
// myRoot.add(unnamedNode);
//}
final ColumnInfo[] COLUMNS = new ColumnInfo[] { getTitleColumnInfo(), getValueColumnInfo() };
ListTreeTableModel model = new ListTreeTableModel(myRoot, COLUMNS);
final TreeTable treeTable = new TreeTable(model) {
@Override
public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
UIUtil.setLineStyleAngled(tableRenderer);
tableRenderer.setRootVisible(false);
tableRenderer.setShowsRootHandles(true);
return tableRenderer;
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellRenderer(row, column);
Object node = treePath.getLastPathComponent();
TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
return renderer == null ? super.getCellRenderer(row, column) : renderer;
}
@Override
public TableCellEditor getCellEditor(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellEditor(row, column);
Object node = treePath.getLastPathComponent();
TableCellEditor editor = COLUMNS[column].getEditor(node);
return editor == null ? super.getCellEditor(row, column) : editor;
}
};
new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));
treeTable.setRootVisible(false);
final JTree tree = treeTable.getTree();
tree.setCellRenderer(myTitleRenderer);
tree.setShowsRootHandles(true);
treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
treeTable.setTableHeader(null);
TreeUtil.expandAll(tree);
treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);
int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
titleColumn.setPreferredWidth(maxWidth);
titleColumn.setMinWidth(maxWidth);
titleColumn.setMaxWidth(maxWidth);
titleColumn.setResizable(false);
final Dimension valueSize = new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
treeTable.setPreferredScrollableViewportSize(new Dimension(maxWidth + valueSize.width + 10, 20));
treeTable.setBackground(UIUtil.getPanelBackground());
treeTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
final Dimension screenSize = treeTable.getToolkit().getScreenSize();
JBScrollPane scroller = new JBScrollPane(treeTable) {
@Override
public Dimension getMinimumSize() {
return super.getPreferredSize();
}
};
final Dimension preferredSize = new Dimension(Math.min(screenSize.width / 2, treeTable.getPreferredSize().width), Math.min(screenSize.height / 2, treeTable.getPreferredSize().height));
getRootPane().setPreferredSize(preferredSize);
return scroller;
}
use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.
the class EnvVariablesTable method createListModel.
@Override
protected ListTableModel createListModel() {
final ColumnInfo name = new ElementsColumnInfoBase<EnvironmentVariable>("Name") {
@Override
public String valueOf(EnvironmentVariable environmentVariable) {
return environmentVariable.getName();
}
@Override
public boolean isCellEditable(EnvironmentVariable environmentVariable) {
return environmentVariable.getNameIsWriteable();
}
@Override
public void setValue(EnvironmentVariable environmentVariable, String s) {
if (s.equals(valueOf(environmentVariable))) {
return;
}
environmentVariable.setName(s);
setModified();
}
@Override
protected String getDescription(EnvironmentVariable environmentVariable) {
return environmentVariable.getDescription();
}
};
final ColumnInfo value = new ElementsColumnInfoBase<EnvironmentVariable>("Value") {
@Override
public String valueOf(EnvironmentVariable environmentVariable) {
return environmentVariable.getValue();
}
@Override
public boolean isCellEditable(EnvironmentVariable environmentVariable) {
return !environmentVariable.getIsPredefined();
}
@Override
public void setValue(EnvironmentVariable environmentVariable, String s) {
if (s.equals(valueOf(environmentVariable))) {
return;
}
environmentVariable.setValue(s);
setModified();
}
@Nullable
@Override
protected String getDescription(EnvironmentVariable environmentVariable) {
return environmentVariable.getDescription();
}
@Nullable
@Override
public TableCellEditor getEditor(EnvironmentVariable variable) {
StringWithNewLinesCellEditor editor = new StringWithNewLinesCellEditor();
editor.setClickCountToStart(1);
return editor;
}
};
return new ListTableModel((new ColumnInfo[] { name, value }));
}
Aggregations