use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class FormEditingUtil method deleteComponents.
public static void deleteComponents(final Collection<? extends RadComponent> selection, boolean deleteEmptyCells) {
if (selection.size() == 0) {
return;
}
final RadRootContainer rootContainer = (RadRootContainer) getRoot(selection.iterator().next());
final Set<String> deletedComponentIds = new HashSet<>();
for (final RadComponent component : selection) {
boolean wasSelected = component.isSelected();
final RadContainer parent = component.getParent();
boolean wasPackedHorz = false;
boolean wasPackedVert = false;
if (parent.getParent() != null && parent.getParent().isXY()) {
final Dimension minSize = parent.getMinimumSize();
wasPackedHorz = parent.getWidth() == minSize.width;
wasPackedVert = parent.getHeight() == minSize.height;
}
iterate(component, new ComponentVisitor() {
public boolean visit(final IComponent c) {
RadComponent rc = (RadComponent) c;
BindingProperty.checkRemoveUnusedField(rootContainer, rc.getBinding(), null);
deletedComponentIds.add(rc.getId());
return true;
}
});
GridConstraints delConstraints = parent.getLayoutManager().isGrid() ? component.getConstraints() : null;
int index = parent.indexOfComponent(component);
parent.removeComponent(component);
if (wasSelected) {
if (parent.getComponentCount() > index) {
parent.getComponent(index).setSelected(true);
} else if (index > 0 && parent.getComponentCount() == index) {
parent.getComponent(index - 1).setSelected(true);
} else {
parent.setSelected(true);
}
}
if (delConstraints != null && deleteEmptyCells) {
deleteEmptyGridCells(parent, delConstraints);
}
if (wasPackedHorz || wasPackedVert) {
final Dimension minSize = parent.getMinimumSize();
Dimension newSize = new Dimension(parent.getWidth(), parent.getHeight());
if (wasPackedHorz) {
newSize.width = minSize.width;
}
if (wasPackedVert) {
newSize.height = minSize.height;
}
parent.setSize(newSize);
}
}
iterate(rootContainer, new ComponentVisitor() {
public boolean visit(final IComponent component) {
RadComponent rc = (RadComponent) component;
for (IProperty p : component.getModifiedProperties()) {
if (p instanceof IntroComponentProperty) {
IntroComponentProperty icp = (IntroComponentProperty) p;
final String value = icp.getValue(rc);
if (deletedComponentIds.contains(value)) {
try {
icp.resetValue(rc);
} catch (Exception e) {
// ignore
}
}
}
}
return true;
}
});
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class FormEditingUtil method canDeleteSelection.
public static boolean canDeleteSelection(final GuiEditor editor) {
final ArrayList<RadComponent> selection = getSelectedComponents(editor);
if (selection.isEmpty())
return false;
final RadRootContainer rootContainer = editor.getRootContainer();
if (rootContainer.getComponentCount() > 0 && selection.contains(rootContainer.getComponent(0))) {
return false;
}
return true;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class FormEditingUtil method selectComponent.
/**
* Selects the component and ensures that the tabbed panes containing the component are
* switched to the correct tab.
*
* @param editor
* @param component the component to select. @return true if the component is enclosed in at least one tabbed pane, false otherwise.
*/
public static boolean selectComponent(final GuiEditor editor, @NotNull final RadComponent component) {
boolean hasTab = false;
RadComponent parent = component;
while (parent.getParent() != null) {
if (parent.getParent().getLayoutManager().switchContainerToChild(parent.getParent(), parent)) {
hasTab = true;
}
parent = parent.getParent();
}
component.setSelected(true);
editor.setSelectionLead(component);
return hasTab;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class FormEditingUtil method getRadComponentAt.
/**
* @param x in editor pane coordinates
* @param y in editor pane coordinates
*/
public static RadComponent getRadComponentAt(final RadRootContainer rootContainer, final int x, final int y) {
Point location = new Point(x, y);
SwingUtilities.convertPointToScreen(location, rootContainer.getDelegee());
Component c = getDeepestEmptyComponentAt(rootContainer.getDelegee(), location);
if (c == null) {
c = SwingUtilities.getDeepestComponentAt(rootContainer.getDelegee(), x, y);
}
RadComponent result = null;
while (c != null) {
if (c instanceof JComponent) {
final RadComponent component = (RadComponent) ((JComponent) c).getClientProperty(RadComponent.CLIENT_PROP_RAD_COMPONENT);
if (component != null) {
if (result == null) {
result = component;
} else {
final Point p = SwingUtilities.convertPoint(rootContainer.getDelegee(), x, y, c);
if (Painter.getResizeMask(component, p.x, p.y) != 0) {
result = component;
}
}
}
}
c = c.getParent();
}
return result;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class AbstractGuiEditorAction method update.
public final void update(AnActionEvent e) {
GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());
if (editor == null) {
e.getPresentation().setVisible(false);
e.getPresentation().setEnabled(false);
} else {
e.getPresentation().setVisible(true);
e.getPresentation().setEnabled(true);
final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor);
update(editor, selection, e);
}
}
Aggregations