2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.uiDesigner
.actions
;
19 import com
.intellij
.uiDesigner
.CaptionSelection
;
20 import com
.intellij
.uiDesigner
.UIDesignerBundle
;
21 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
22 import com
.jgoodies
.forms
.layout
.FormLayout
;
24 import java
.util
.List
;
25 import java
.util
.ArrayList
;
30 public class UngroupRowsColumnsAction
extends RowColumnAction
{
31 public UngroupRowsColumnsAction() {
32 super(UIDesignerBundle
.message("action.ungroup.columns"), null, UIDesignerBundle
.message("action.ungroup.rows"), null);
36 public void update(final AnActionEvent e
) {
38 CaptionSelection selection
= e
.getData(CaptionSelection
.DATA_KEY
);
39 if (selection
!= null) {
40 e
.getPresentation().setEnabled(selection
.getContainer() != null &&
41 selection
.getContainer().getLayout() instanceof FormLayout
&&
42 GroupRowsColumnsAction
.isGrouped(selection
));
46 protected void actionPerformed(CaptionSelection selection
) {
47 FormLayout layout
= (FormLayout
) selection
.getContainer().getLayout();
48 int[][] oldGroups
= selection
.isRow() ? layout
.getRowGroups() : layout
.getColumnGroups();
49 List
<int[]> newGroups
= new ArrayList
<int[]>();
50 int[] selInts
= selection
.getSelection();
51 for(int[] group
: oldGroups
) {
52 if (!GroupRowsColumnsAction
.intersect(group
, selInts
)) {
56 int[][] newGroupArray
= newGroups
.toArray(new int[newGroups
.size()][]);
57 if (selection
.isRow()) {
58 layout
.setRowGroups(newGroupArray
);
61 layout
.setColumnGroups(newGroupArray
);