From 3f32486fd88250b9a0faeaa75526d3e38ce287d0 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Wed, 3 May 2017 15:15:05 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-2537=20=E5=A4=9A=E5=B1=82=E6=AC=A1?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E5=B7=A5=E5=85=B7=E6=A0=8F=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=BB=86=E7=B2=92=E5=BA=A6=E8=AE=BE=E7=BD=AE=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/AuthorityEditToolBarPane.java | 249 +++++- .../ElementCasePaneAuthorityEditPane.java | 836 +++++++++++++++++- 2 files changed, 1083 insertions(+), 2 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java b/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java index d464d8f48..296d72b96 100644 --- a/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java +++ b/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java @@ -1 +1,248 @@ -package com.fr.design.mainframe; import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.UIConstants; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.roleAuthority.ReportAndFSManagePane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.webattr.ToolBarButton; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.stable.StringUtils; import javax.swing.*; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.List; /** * 用于在权限编辑状态对工具栏的元素进行权限编辑的面板 * Author : daisy * Date: 13-9-18 * Time: 下午2:15 */ public class AuthorityEditToolBarPane extends AuthorityPropertyPane { private static final int TITLE_HEIGHT = 19; private AuthorityEditPane authorityEditPane = null; private AuthorityToolBarPane authorityToolBarPane; private String[] selectedPathArray; public AuthorityEditToolBarPane(List buttonlists) { super(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); this.setLayout(new BorderLayout()); this.setBorder(null); UILabel authorityTitle = new UILabel(Inter.getLocText(new String[]{"DashBoard-Potence", "Edit"})) { @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, TITLE_HEIGHT); } }; authorityTitle.setHorizontalAlignment(SwingConstants.CENTER); authorityTitle.setVerticalAlignment(SwingConstants.CENTER); JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); northPane.add(authorityTitle, BorderLayout.CENTER); northPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); this.add(northPane, BorderLayout.NORTH); authorityEditPane = new AuthorityEditPane(buttonlists); this.add(authorityEditPane, BorderLayout.CENTER); } public void setAuthorityToolBarPane(AuthorityToolBarPane authorityToolBarPane) { this.authorityToolBarPane = authorityToolBarPane; } public void populate() { authorityToolBarPane.populateAuthority(); signelSelection(); authorityEditPane.populateDetials(); } private void signelSelection() { JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (jTemplate.isJWorkBook()) { //清参数面板 jTemplate.removeParameterPaneSelection(); //清报表主体 jTemplate.removeTemplateSelection(); } } private class AuthorityEditPane extends JPanel { private static final int TOP_GAP = 11; private static final int LEFT_GAP = 8; private static final int ALIGNMENT_GAP = -3; private UILabel type = null; private UILabel name = null; private JPanel checkPane = null; private List buttonlists; private UICheckBox buttonVisible = new UICheckBox(Inter.getLocText("Widget-Visible")); private ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { String selectedRole = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); initSelectedselectedPathArray(); if (ComparatorUtils.equals(selectedRole, Inter.getLocText("Role"))) { return; } if (selectedRole == null) { return; } if (selectedPathArray == null) { return; } for (int t = 0; t _buttonlists = AuthorityEditPane.this.buttonlists; for (int j = 0; j < _buttonlists.size(); j++) { if (_buttonlists.get(j).isSelected()) { //由引擎实现保存进模板报表 authorityToolBarPane.setAuthorityWebAttr(_buttonlists.get(j).getWidget(), checkbox.isSelected(), selectedPathArray[t]); } } } } }; private void initSelectedselectedPathArray () { TreePath[] selectionPaths = ReportAndFSManagePane.getInstance().getRoleTree().getCheckBoxTreeSelectionModel().getSelectionPaths(); if (selectionPaths.length == 1){ if(((ExpandMutableTreeNode)(selectionPaths[0].getLastPathComponent())).getChildCount() > 0){ ExpandMutableTreeNode node = (ExpandMutableTreeNode) ((ExpandMutableTreeNode)(selectionPaths[0].getLastPathComponent())).getLastChild(); selectedPathArray = new String[node.getChildCount()]; for (int i = 0 ; i < node.getChildCount(); i++) { ExpandMutableTreeNode n = (ExpandMutableTreeNode) node.getChildAt(i); String nodeName = n.getUserObject().toString(); selectedPathArray[i] = nodeName; } } else { selectedPathArray = pathToString(selectionPaths); } } else { selectedPathArray = pathToString(selectionPaths); } } protected String[] pathToString(TreePath[] path) { String roles = StringUtils.EMPTY; if(path == null || path.length == 0){ return null; } for(TreePath tempPath:path){ String temp = tempPath.toString(); boolean isTrue = temp.length() > 0 && temp.charAt(0) == '[' && temp.endsWith("]"); if (isTrue) { temp = temp.substring(1, temp.length() - 1); String[] selectedRoles = temp.split(","); String role = selectedRoles[2].trim(); if(roles.isEmpty()){ roles = role; }else{ roles = roles + "," + role; } } } String[] selectedRole = roles.split(","); return selectedRole; } public AuthorityEditPane(List buttonlists) { setLayout(new BorderLayout()); type = new UILabel(); name = new UILabel(); checkPane = new JPanel(); checkPane.setLayout(new BorderLayout()); this.add(layoutText(), BorderLayout.WEST); this.add(layoutPane(), BorderLayout.CENTER); this.setBorder(BorderFactory.createEmptyBorder(TOP_GAP, LEFT_GAP, 0, 0)); this.buttonlists = buttonlists; buttonVisible.addItemListener(itemListener); } private JPanel layoutText() { double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("Type") + ":", SwingConstants.RIGHT)}, new Component[]{new UILabel(Inter.getLocText("WF-Name") + ":", SwingConstants.RIGHT)}, new Component[]{new UILabel(Inter.getLocText("DashBoard-Potence") + ":", SwingConstants.RIGHT)}, }; double[] rowSize = {p, p, p}; double[] columnSize = {p}; int[][] rowCount = {{1}, {1}, {1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel layoutPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{type}, new Component[]{name}, new Component[]{checkPane}, }; double[] rowSize = {p, p, p}; double[] columnSize = {f}; int[][] rowCount = {{1}, {1}, {1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } /** * 更新权限编辑面板的具体内容:类型、名称、权限面板 */ public void populateDetials() { populateName(); populateType(); populateCheckPane(); checkVisibleCheckBoxes(); } private void checkVisibleCheckBoxes() { buttonVisible.removeItemListener(itemListener); String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (selected == null) { buttonVisible.setSelected(true); } for (int i = 0; i < buttonlists.size(); i++) { if (buttonlists.get(i).isSelected()) { buttonVisible.setSelected(!buttonlists.get(i).isDoneAuthorityEdited(selected)); break; } } buttonVisible.addItemListener(itemListener); } public void populateType() { if (name.getText() == "") { type.setText(""); } else { type.setText(Inter.getLocText(new String[]{"ReportServerP-Toolbar", "Form-Button"})); } } public void populateName() { String names = ""; for (int i = 0; i < buttonlists.size(); i++) { if (buttonlists.get(i).isSelected()) { names += "," + buttonlists.get(i).getNameOption().optionName(); } } if (names != "") { names = names.substring(1); } name.setText(names); } public void populateCheckPane() { checkPane.removeAll(); if (name.getText() == "") { return; } double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("Form-Button"), SwingConstants.LEFT), buttonVisible}, }; double[] rowSize = {p, p}; double[] columnSize = {p, p, f}; int[][] rowCount = {{1, 1, 1}, {1, 1, 1}}; JPanel check = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); checkPane.add(check, BorderLayout.CENTER); checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); } } } \ No newline at end of file +package com.fr.design.mainframe; + +import com.fr.design.constants.LayoutConstants; +import com.fr.design.constants.UIConstants; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.roleAuthority.ReportAndFSManagePane; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.design.webattr.ToolBarButton; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.List; + +/** + * 用于在权限编辑状态对工具栏的元素进行权限编辑的面板 + * Author : daisy + * Date: 13-9-18 + * Time: 下午2:15 + */ +public class AuthorityEditToolBarPane extends AuthorityPropertyPane { + + private static final int TITLE_HEIGHT = 19; + private AuthorityEditPane authorityEditPane = null; + private AuthorityToolBarPane authorityToolBarPane; + private String[] selectedPathArray; + + public AuthorityEditToolBarPane(List buttonlists) { + super(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + this.setLayout(new BorderLayout()); + this.setBorder(null); + UILabel authorityTitle = new UILabel(Inter.getLocText(new String[]{"DashBoard-Potence", "Edit"})) { + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, TITLE_HEIGHT); + } + }; + authorityTitle.setHorizontalAlignment(SwingConstants.CENTER); + authorityTitle.setVerticalAlignment(SwingConstants.CENTER); + JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + northPane.add(authorityTitle, BorderLayout.CENTER); + northPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); + this.add(northPane, BorderLayout.NORTH); + authorityEditPane = new AuthorityEditPane(buttonlists); + this.add(authorityEditPane, BorderLayout.CENTER); + } + + public void setAuthorityToolBarPane(AuthorityToolBarPane authorityToolBarPane) { + this.authorityToolBarPane = authorityToolBarPane; + } + + + public void populate() { + authorityToolBarPane.populateAuthority(); + signelSelection(); + authorityEditPane.populateDetials(); + } + + + private void signelSelection() { + JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (jTemplate.isJWorkBook()) { + //清参数面板 + jTemplate.removeParameterPaneSelection(); + //清报表主体 + jTemplate.removeTemplateSelection(); + } + } + + + private class AuthorityEditPane extends JPanel { + private static final int TOP_GAP = 11; + private static final int LEFT_GAP = 8; + private static final int ALIGNMENT_GAP = -3; + private UILabel type = null; + private UILabel name = null; + private JPanel checkPane = null; + private List buttonlists; + private UICheckBox buttonVisible = new UICheckBox(Inter.getLocText("Widget-Visible")); + private ItemListener itemListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + String selectedRole = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + initSelectedPathArray(); + if (ComparatorUtils.equals(selectedRole, Inter.getLocText("Role")) || selectedRole == + null || selectedPathArray == null) { + return; + } + for (int t = 0; t < selectedPathArray.length; t++) { + for (int i = 0; i < buttonlists.size(); i++) { + if (buttonlists.get(i).isSelected()) { + buttonlists.get(i).changeAuthorityState(selectedPathArray[t], buttonVisible.isSelected()); + authorityToolBarPane.repaint(); + } + } + HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().fireTargetModified(); + RolesAlreadyEditedPane.getInstance().refreshDockingView(); + UICheckBox checkbox = (UICheckBox) e.getSource(); + List btns = AuthorityEditPane.this.buttonlists; + for (int j = 0; j < btns.size(); j++) { + if (btns.get(j).isSelected()) { + //由引擎实现保存进模板报表 + authorityToolBarPane.setAuthorityWebAttr(btns.get(j).getWidget(), checkbox.isSelected(), selectedPathArray[t]); + } + } + } + } + }; + + /** + * @see ElementCasePaneAuthorityEditPane initSelectedPathArray() + */ + private void initSelectedPathArray() { + TreePath[] selectionPaths = ReportAndFSManagePane.getInstance().getRoleTree().getCheckBoxTreeSelectionModel().getSelectionPaths(); + if (selectionPaths.length == 1) { + if (((ExpandMutableTreeNode) (selectionPaths[0].getLastPathComponent())).getChildCount() > 0) { + ExpandMutableTreeNode node = (ExpandMutableTreeNode) ((ExpandMutableTreeNode) (selectionPaths[0].getLastPathComponent())).getLastChild(); + selectedPathArray = new String[node.getChildCount()]; + for (int i = 0; i < node.getChildCount(); i++) { + ExpandMutableTreeNode n = (ExpandMutableTreeNode) node.getChildAt(i); + String nodeName = n.getUserObject().toString(); + selectedPathArray[i] = nodeName; + } + } else { + selectedPathArray = ElementCasePaneAuthorityEditPane.pathToString(selectionPaths); + } + } else { + selectedPathArray = ElementCasePaneAuthorityEditPane.pathToString(selectionPaths); + } + + } + + public AuthorityEditPane(List buttonlists) { + setLayout(new BorderLayout()); + type = new UILabel(); + name = new UILabel(); + checkPane = new JPanel(); + checkPane.setLayout(new BorderLayout()); + this.add(layoutText(), BorderLayout.WEST); + this.add(layoutPane(), BorderLayout.CENTER); + this.setBorder(BorderFactory.createEmptyBorder(TOP_GAP, LEFT_GAP, 0, 0)); + this.buttonlists = buttonlists; + buttonVisible.addItemListener(itemListener); + } + + private JPanel layoutText() { + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("Type") + ":", SwingConstants.RIGHT)}, + new Component[]{new UILabel(Inter.getLocText("WF-Name") + ":", SwingConstants.RIGHT)}, + new Component[]{new UILabel(Inter.getLocText("DashBoard-Potence") + ":", SwingConstants.RIGHT)}, + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {p}; + int[][] rowCount = {{1}, {1}, {1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + + private JPanel layoutPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{type}, + new Component[]{name}, + new Component[]{checkPane}, + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}, {1}, {1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + /** + * 更新权限编辑面板的具体内容:类型、名称、权限面板 + */ + public void populateDetials() { + populateName(); + populateType(); + populateCheckPane(); + checkVisibleCheckBoxes(); + } + + private void checkVisibleCheckBoxes() { + buttonVisible.removeItemListener(itemListener); + String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (selected == null) { + buttonVisible.setSelected(true); + } + for (int i = 0; i < buttonlists.size(); i++) { + if (buttonlists.get(i).isSelected()) { + buttonVisible.setSelected(!buttonlists.get(i).isDoneAuthorityEdited(selected)); + break; + } + } + buttonVisible.addItemListener(itemListener); + } + + + public void populateType() { + if (name.getText() == "") { + type.setText(""); + } else { + type.setText(Inter.getLocText(new String[]{"ReportServerP-Toolbar", "Form-Button"})); + } + } + + public void populateName() { + String names = ""; + for (int i = 0; i < buttonlists.size(); i++) { + if (buttonlists.get(i).isSelected()) { + names += "," + buttonlists.get(i).getNameOption().optionName(); + } + } + if (names != "") { + names = names.substring(1); + } + name.setText(names); + } + + public void populateCheckPane() { + checkPane.removeAll(); + if (name.getText() == "") { + return; + } + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("Form-Button"), SwingConstants.LEFT), buttonVisible}, + }; + double[] rowSize = {p, p}; + double[] columnSize = {p, p, f}; + int[][] rowCount = {{1, 1, 1}, {1, 1, 1}}; + JPanel check = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + checkPane.add(check, BorderLayout.CENTER); + checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java b/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java index 3f9a717dd..f654b3d29 100644 --- a/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java +++ b/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java @@ -1 +1,835 @@ -package com.fr.design.mainframe; import com.fr.design.constants.LayoutConstants; import com.fr.design.editor.ValueEditorPane; import com.fr.design.editor.ValueEditorPaneFactory; import com.fr.design.event.UIObserverListener; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.toolbar.AuthorityEditToolBarComponent; import com.fr.design.roleAuthority.ReportAndFSManagePane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.form.ui.Widget; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.FloatSelection; import com.fr.grid.selection.Selection; import com.fr.js.NameJavaScriptGroup; import com.fr.report.cell.AbstractCellElement; import com.fr.report.cell.DefaultTemplateCellElement; import com.fr.report.cell.FloatElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.TemplateElementCase; import com.fr.report.worksheet.WorkSheet; import com.fr.stable.ColumnRow; import com.fr.stable.StringUtils; import javax.swing.*; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; /** * Author : daisy * Date: 13-9-4 * Time: 下午4:01 */ public class ElementCasePaneAuthorityEditPane extends AuthorityEditPane { private static final int WIDGET_VISIBLE = 0; private static final int WIDGET_USABLE = 1; private static final int CELL = 2; private static final int HYPER_LINK = 3; private static final int FLOAT_SELECTION = 3; private static final int NEW_VALUE = 4; //新值下面的编辑器的宽度 private static final int NEW_PANE_WIDTH = 120; private UICheckBox floatElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); private UICheckBox cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); private UICheckBox widgetVisible = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); private UICheckBox widgetAvailable = new UICheckBox(Inter.getLocText("FR-Designer_Enabled")); private UICheckBox gridColumnRowVisible = new UICheckBox(Inter.getLocText("FR-Designer_Hide")); private UICheckBox newValue = new UICheckBox(Inter.getLocText("FR-Designer_New_Value")); private ValueEditorPane valueEditor = ValueEditorPaneFactory.createBasicValueEditorPane(NEW_PANE_WIDTH); private UICheckBox[] hyperlinkCheckBoxes = null; private ElementCasePane elementCasePane = null; private int selectionType = CellSelection.NORMAL; private CellSelection cellSelection; private FloatSelection floatSelection; private boolean isAllHasWidget; private boolean isAllHasHyperlink; private String[] selectedPathArray; private UIObserverListener observerListener = new UIObserverListener() { @Override public void doChange() { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(NEW_VALUE)) { elementCasePane.fireTargetModified(); } } }; private ItemListener newValuelistener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(NEW_VALUE)) { valueEditor.setEnabled(newValue.isSelected()); doAfterAuthority(); } } }; private ItemListener columnRowAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null) { return; } boolean isDone = false; if (selectionType == CellSelection.CHOOSE_COLUMN) { isDone = setAuthorityColumn(); } else { isDone = setAuthorityRow(); } if (isDone) { doAfterAuthority(); } } }; private ItemListener floatElementAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || floatSelection == null) { return; } if (setLFloatAuthorityStyle()) { doAfterAuthority(); } } }; private ItemListener cellRolesAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(CELL)) { doAfterAuthority(); } } }; private ItemListener widgetVisibleRoleAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(WIDGET_VISIBLE)) { doAfterAuthority(); } } }; private ItemListener widgetUsableAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(WIDGET_USABLE)) { doAfterAuthority(); } } }; public ElementCasePaneAuthorityEditPane(ElementCasePane elementCasePane) { super(elementCasePane); this.elementCasePane = elementCasePane; initCheckBoxesState(); initListener(); } private void doAfterAuthority() { elementCasePane.repaint(); elementCasePane.fireTargetModified(); RolesAlreadyEditedPane.getInstance().refreshDockingView(); RolesAlreadyEditedPane.getInstance().setReportAndFSSelectedRoles(); RolesAlreadyEditedPane.getInstance().repaint(); checkCheckBoxes(); } private boolean setAuthorityColumn() { initSelectedselectedPathArray(); String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { return false; } if (selectedRoles == null) { return false; } if (selectedPathArray == null) { return false; } final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); boolean isVisible = !gridColumnRowVisible.isSelected(); for (int t = 0; t= 0; j--) { for (int i = cellRectangle.width - 1; i >= 0; i--) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); if (editCellElement == null) { editCellElement = new DefaultTemplateCellElement(column, row); elementCase.addCellElement(editCellElement); } else { // 对于合并的格子,我们不多次计算的权限. if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { continue; } } if (type == CELL) { editCellElement.changeAuthorityState(selectedPathArray[t], cellElementVisibleCheckBoxes.isSelected()); } else if (type == NEW_VALUE) { editCellElement.changeNewValueAuthorityState(selectedPathArray[t], newValue.isSelected(), valueEditor.update()); } else if (type == WIDGET_VISIBLE) { Widget widget = editCellElement.getWidget(); widget.changeVisibleAuthorityState(selectedPathArray[t], widgetVisible.isSelected()); } else { Widget widget = editCellElement.getWidget(); widget.changeUsableAuthorityState(selectedPathArray[t], widgetAvailable.isSelected()); } } } } } return true; } private void initSelectedselectedPathArray () { TreePath[] selectionPaths = ReportAndFSManagePane.getInstance().getRoleTree().getCheckBoxTreeSelectionModel().getSelectionPaths(); if (selectionPaths.length == 1){ if(((ExpandMutableTreeNode)(selectionPaths[0].getLastPathComponent())).getChildCount() > 0){ ExpandMutableTreeNode node = (ExpandMutableTreeNode) ((ExpandMutableTreeNode)(selectionPaths[0].getLastPathComponent())).getLastChild(); System.out.printf(node.getUserObject().toString()); selectedPathArray = new String[node.getChildCount()]; for (int i = 0; i < node.getChildCount(); i++) { ExpandMutableTreeNode n = (ExpandMutableTreeNode) node.getChildAt(i); String nodeName = n.getUserObject().toString(); selectedPathArray[i] = nodeName; } } else { selectedPathArray = pathToString(selectionPaths); } } else { selectedPathArray = pathToString(selectionPaths); } } protected String[] pathToString(TreePath[] path) { String roles = StringUtils.EMPTY; if(path == null || path.length == 0){ return null; } for(TreePath tempPath:path){ String temp = tempPath.toString(); boolean isTrue = temp.length() > 0 && temp.charAt(0) == '[' && temp.endsWith("]"); if (isTrue) { temp = temp.substring(1, temp.length() - 1); String[] selectedRoles = temp.split(","); String role = selectedRoles[2].trim(); if(roles.isEmpty()){ roles = role; }else{ roles = roles + "," + role; } } } String[] selectedRole = roles.split(","); return selectedRole; } /** * 选中的单元格的乐见状态以第一个单元格为齐 */ public void initCheckBoxesState() { final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); if (cellSelection == null) { cellElementVisibleCheckBoxes.setSelected(true); } else { Rectangle cellRectangle = cellSelection.getCellRectangle(0); DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellRectangle.x, cellRectangle.y); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(cellRectangle.x, cellRectangle.y); } boolean firstCellDoneaAuthority = cellElement.isDoneAuthority( ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName()); cellElementVisibleCheckBoxes.setSelected(!firstCellDoneaAuthority); } widgetAvailable.setEnabled(cellElementVisibleCheckBoxes.isSelected()); widgetVisible.setEnabled(cellElementVisibleCheckBoxes.isSelected()); } private void initListener() { cellElementVisibleCheckBoxes.addItemListener(cellRolesAuthorityListener); widgetVisible.addItemListener(widgetVisibleRoleAuthorityListener); widgetAvailable.addItemListener(widgetUsableAuthorityListener); floatElementVisibleCheckBoxes.addItemListener(floatElementAuthorityListener); gridColumnRowVisible.addItemListener(columnRowAuthorityListener); newValue.addItemListener(newValuelistener); valueEditor.registerChangeListener(observerListener); } private void removeListener() { cellElementVisibleCheckBoxes.removeItemListener(cellRolesAuthorityListener); widgetVisible.removeItemListener(widgetVisibleRoleAuthorityListener); widgetAvailable.removeItemListener(widgetUsableAuthorityListener); floatElementVisibleCheckBoxes.removeItemListener(floatElementAuthorityListener); gridColumnRowVisible.removeItemListener(columnRowAuthorityListener); newValue.removeItemListener(newValuelistener); valueEditor.registerChangeListener(null); } private void addHyperlinkListener() { cellElementVisibleCheckBoxes.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (hyperlinkCheckBoxes != null) { for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); if (!cellElementVisibleCheckBoxes.isSelected()) { hyperlinkCheckBoxes[i].setSelected(false); } } } } }); for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { hyperlinkCheckBoxes[i].addItemListener(cellRolesAuthorityListener); } } /** * 更新适合的类型 */ public void populateType() { if (selectionType == CellSelection.NORMAL) { type.setText(Inter.getLocText("FR-Designer_Cell")); } else if (selectionType == CellSelection.CHOOSE_ROW) { type.setText(Inter.getLocText("FR-Designer_Row")); } else if (selectionType == CellSelection.CHOOSE_COLUMN) { type.setText(Inter.getLocText("FR-Designer_Column")); } else { type.setText(Inter.getLocText("M_Insert-Float")); } } /** * 名字 */ public void populateName() { if (selectionType == CellSelection.NORMAL) { name.setText(getCellSelectionName()); } else if (selectionType == CellSelection.CHOOSE_ROW || selectionType == CellSelection.CHOOSE_COLUMN) { name.setText(getCellColumnRowName()); } else { name.setText(getFloatSelectionName()); } } private String getCellSelectionName() { String nameText = ""; int count = cellSelection.getCellRectangleCount(); for (int rect = 0; rect < count; rect++) { nameText += ","; Rectangle cellRectangle = cellSelection.getCellRectangle(rect); ColumnRow beginCR = ColumnRow.valueOf(cellRectangle.x, cellRectangle.y); nameText += beginCR.toString(); if (cellRectangle.width * cellRectangle.height != 1) { ColumnRow endCR = ColumnRow.valueOf(cellRectangle.width + cellRectangle.x - 1, cellRectangle.height + cellRectangle.y - 1); nameText += ":" + endCR.toString(); } } return nameText.substring(1); } private String getCellColumnRowName() { int count = cellSelection.getCellRectangleCount(); String nameText = ""; ColumnRow cr = ColumnRow.valueOf(cellSelection.getColumn(), cellSelection.getRow()); if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && count == 1) { if (cellSelection.getColumnSpan() == 1) { nameText = cr.toString().substring(0, 1); } else { ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, cellSelection.getRow() + cellSelection.getRowSpan() - 1); nameText = cr.toString().substring(0, 1) + "-" + endCr.toString().substring(0, 1); } } else if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && count == 1) { if (cellSelection.getRowSpan() == 1) { nameText = cr.toString().substring(1); } else { ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, cellSelection.getRow() + cellSelection.getRowSpan() - 1); nameText = cr.toString().substring(1) + "-" + endCr.toString().substring(1); } } return nameText; } private String getFloatSelectionName() { return floatSelection.getSelectedFloatName(); } private void mutilRect(CellSelection cellSelection) { isAllHasWidget = true; isAllHasHyperlink = true; int count = cellSelection.getCellRectangleCount(); final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); for (int rect = 0; rect < count; rect++) { Rectangle cellRectangle = cellSelection.getCellRectangle(rect); for (int j = 0; j < cellRectangle.height; j++) { for (int i = 0; i < cellRectangle.width; i++) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(column, row); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); } if (cellElement.getCellWidgetAttr() == null) { isAllHasWidget = false; } if (cellElement.getNameHyperlinkGroup() == null) { isAllHasHyperlink = false; } } } } } /** * 更新适合的pane * * @return 返回Pane */ public JPanel populateCheckPane() { checkPane.removeAll(); if (selectionType == CellSelection.NORMAL) { populateCellSelectionCheckPane(checkPane); } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { populateColumnRowCheckPane(checkPane); } else if (selectionType == FLOAT_SELECTION) { populateFloatSelectionCheckPane(checkPane); } checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); return checkPane; } private void populateColumnRowCheckPane(JPanel checkPane) { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{gridColumnRowVisible} }; double[] rowSize = {p}; double[] columnSize = {f}; int[][] rowCount = {{1}}; checkPane.add( TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM) , BorderLayout.WEST); } private void populateFloatSelectionCheckPane(JPanel checkPane) { checkPane.add(populateFloatElementCheckPane(), BorderLayout.WEST); } private void populateCellSelectionCheckPane(JPanel checkPane) { if (elementCasePane.isSelectedOneCell()) { //只选中了一个单元格 final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellSelection.getColumn(), cellSelection.getRow()); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); } //单元格带控件 if (cellElement.getCellWidgetAttr() != null) { checkPane.add(populateWidgetCheckPane(), BorderLayout.WEST); } else { checkPane.add(populatCellCheckPane(), BorderLayout.WEST); } } else { //批量选中单元格 mutilRect(cellSelection); if (!isAllHasWidget && !isAllHasHyperlink) { checkPane.add(populateMutilCellCheckPane(), BorderLayout.WEST); } else if (isAllHasWidget) { checkPane.add(populateMutilWidgetCheckPane(), BorderLayout.WEST); } } } /** * 对单元格区域进行操作时的权限编辑页面 ,对应的角色的populate */ public void populateDetials() { //做模式标记,此时鼠标焦点是在报表主体,为下一次退出权限编辑时做准备 HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().setAuthorityMode(false); TemplateElementCase templateElementCase = elementCasePane.getEditingElementCase(); if (templateElementCase instanceof WorkSheet) { ((WorkSheet) templateElementCase).setPaintSelection(true); } signelSelection(); Selection selection = elementCasePane.getSelection(); if (selection instanceof CellSelection) { selectionType = CellSelection.NORMAL; this.cellSelection = ((CellSelection) selection).clone(); this.floatSelection = null; judgeChooseCR(); } else if (selection instanceof FloatSelection) { selectionType = FLOAT_SELECTION; cellSelection = null; floatSelection = new FloatSelection(((FloatSelection) selection).getSelectedFloatName()); } populateType(); populateName(); populateCheckPane(); checkCheckBoxes(); } //判断是否选择的行列 private void judgeChooseCR() { if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && cellSelection.getCellRectangleCount() == 1) { selectionType = CellSelection.CHOOSE_COLUMN; } if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && cellSelection.getCellRectangleCount() == 1) { selectionType = CellSelection.CHOOSE_ROW; } } //实现单选 private void signelSelection() { JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (jTemplate.isJWorkBook()) { //清工具栏 JComponent component = DesignerContext.getDesignerFrame().getToolbarComponent(); if (component instanceof AuthorityEditToolBarComponent) { ((AuthorityEditToolBarComponent) component).removeSelection(); } //清参数面板 jTemplate.removeParameterPaneSelection(); } } private JPanel populateFloatElementCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("M_Insert-Float"), SwingConstants.LEFT), floatElementVisibleCheckBoxes} }; double[] rowSize = {p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateWidgetCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, new Component[]{null, newValue}, new Component[]{null, valueEditor}, new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, new Component[]{null, widgetAvailable} }; double[] rowSize = {p, p, p, p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateMutilWidgetCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, new Component[]{null, widgetAvailable} }; double[] rowSize = {p, p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateMutilCellCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{cellElementVisibleCheckBoxes}, }; double[] rowSize = {p}; double[] columnSize = {f}; int[][] rowCount = {{1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populatCellCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{cellElementVisibleCheckBoxes}, new Component[]{newValue}, new Component[]{valueEditor} }; double[] rowSize = {p, p, p}; double[] columnSize = {f}; int[][] rowCount = {{1}, {1}, {1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } public TemplateCellElement getFirstCell() { final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); Rectangle cellRectangle = cellSelection.getCellRectangle(0); // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 TemplateCellElement firstCell = null; for (int j = cellRectangle.height - 1; j >= 0; j--) { for (int i = cellRectangle.width - 1; i >= 0; i--) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); if (editCellElement != null) { // 对于合并的格子,我们不多次计算的权限. if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { continue; } firstCell = editCellElement; } } } return firstCell; } private void checkCheckBoxes() { String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); removeListener(); if (selectionType == CellSelection.NORMAL) { checkCellSelectionCkeckboxes(selected); } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { checkColumnRowCheckBoxes(selected); } else if (selectionType == FLOAT_SELECTION) { checkFloatSelectionCkeckboxes(selected); } initListener(); } private void checkCellSelectionCkeckboxes(String selected) { TemplateCellElement firstCell = getFirstCell(); if (firstCell == null) { resetCellElementCheckBoxes(); return; } cellElementVisibleCheckBoxes.setSelected(!firstCell.isDoneAuthority(selected)); newValue.setEnabled(!firstCell.isDoneAuthority(selected)); if (!firstCell.isDoneAuthority(selected)) { newValue.setSelected(firstCell.isDoneNewValueAuthority(selected)); if (newValue.isSelected()) { valueEditor.setEnabled(true); valueEditor.populate(firstCell.getCellPrivilegeControl().getNewValueMap().get(selected)); } else { valueEditor.setEnabled(false); } } else { newValue.setSelected(false); valueEditor.setEnabled(false); } populateWidgetButton(firstCell.getWidget(), selected, firstCell); } private void populateWidgetButton(Widget widget, String selected, TemplateCellElement firstCell){ if(widget == null){ return; } if(widget.isVisible()){ widgetVisible.setSelected(!widget.isDoneVisibleAuthority(selected)); widgetVisible.setEnabled(!firstCell.isDoneAuthority(selected)); }else{ widgetVisible.setSelected(widget.isVisibleAuthority(selected)); } if(widget.isEnabled()){ widgetAvailable.setSelected(!widget.isDoneUsableAuthority(selected)); widgetAvailable.setEnabled(!widget.isDoneVisibleAuthority(selected)); }else{ widgetAvailable.setSelected(widget.isUsableAuthority(selected)); } } private void resetCellElementCheckBoxes() { cellElementVisibleCheckBoxes.setSelected(true); widgetVisible.setSelected(true); widgetVisible.setEnabled(true); widgetAvailable.setSelected(true); widgetAvailable.setEnabled(true); newValue.setSelected(false); valueEditor.setEnabled(false); } private void checkColumnRowCheckBoxes(String selected) { if (cellSelection == null) { gridColumnRowVisible.setSelected(false); return; } TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); boolean isInside = selectionType == CellSelection.CHOOSE_COLUMN ? elementCase.getColumnPrivilegeControl(cellSelection.getColumn()).checkInvisible(selected) : elementCase.getRowPrivilegeControl(cellSelection.getRow()).checkInvisible(selected); gridColumnRowVisible.setSelected(isInside); } private void checkFloatSelectionCkeckboxes(String selected) { String name = floatSelection.getSelectedFloatName(); TemplateElementCase ec = elementCasePane.getEditingElementCase(); FloatElement fe = ec.getFloatElement(name); floatElementVisibleCheckBoxes.setSelected(!fe.isDoneAuthority(selected)); } private JPanel populateHyperlinkCheckPane(AbstractCellElement cellElement) { NameJavaScriptGroup linkGroup = cellElement.getNameHyperlinkGroup(); //超链接的个数+单元格可见的操作 hyperlinkCheckBoxes = new UICheckBox[linkGroup.size()]; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[hyperlinkCheckBoxes.length + 1][]; if (linkGroup.size() == 1) { components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; } else { components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(linkGroup.getNameHyperlink(0).getName() + Inter.getLocText("FR-Designer_Visible"))}; for (int i = 1; i < hyperlinkCheckBoxes.length; i++) { components[i + 1] = new Component[]{null, hyperlinkCheckBoxes[i] = new UICheckBox(linkGroup.getNameHyperlink(i).getName() + Inter.getLocText("FR-Designer_Visible"))}; } } for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); } addHyperlinkListener(); double[] rowSize = new double[hyperlinkCheckBoxes.length + 1]; int[][] rowCount = new int[hyperlinkCheckBoxes.length + 1][]; for (int i = 0; i < hyperlinkCheckBoxes.length + 1; i++) { rowSize[i] = p; rowCount[i] = new int[]{1, 1}; } double[] columnSize = {p, f}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateMutilHyperlinkCheckPane() { //超链接的个数+单元格可见的操作 hyperlinkCheckBoxes = new UICheckBox[1]; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[2][]; components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; hyperlinkCheckBoxes[0].setEnabled(cellElementVisibleCheckBoxes.isSelected()); addHyperlinkListener(); double[] rowSize = {p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } } \ No newline at end of file +package com.fr.design.mainframe; + +import com.fr.design.constants.LayoutConstants; +import com.fr.design.editor.ValueEditorPane; +import com.fr.design.editor.ValueEditorPaneFactory; +import com.fr.design.event.UIObserverListener; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.toolbar.AuthorityEditToolBarComponent; +import com.fr.design.roleAuthority.ReportAndFSManagePane; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.form.ui.Widget; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.js.NameJavaScriptGroup; +import com.fr.report.cell.AbstractCellElement; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.FloatElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.worksheet.WorkSheet; +import com.fr.stable.ColumnRow; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; + +/** + * Author : daisy + * Date: 13-9-4 + * Time: 下午4:01 + */ +public class ElementCasePaneAuthorityEditPane extends AuthorityEditPane { + private static final int WIDGET_VISIBLE = 0; + private static final int WIDGET_USABLE = 1; + private static final int CELL = 2; + private static final int HYPER_LINK = 3; + private static final int FLOAT_SELECTION = 3; + private static final int NEW_VALUE = 4; + //新值下面的编辑器的宽度 + private static final int NEW_PANE_WIDTH = 120; + + + private UICheckBox floatElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); + private UICheckBox cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); + private UICheckBox widgetVisible = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); + private UICheckBox widgetAvailable = new UICheckBox(Inter.getLocText("FR-Designer_Enabled")); + private UICheckBox gridColumnRowVisible = new UICheckBox(Inter.getLocText("FR-Designer_Hide")); + private UICheckBox newValue = new UICheckBox(Inter.getLocText("FR-Designer_New_Value")); + private ValueEditorPane valueEditor = ValueEditorPaneFactory.createBasicValueEditorPane(NEW_PANE_WIDTH); + private UICheckBox[] hyperlinkCheckBoxes = null; + private ElementCasePane elementCasePane = null; + private int selectionType = CellSelection.NORMAL; + private CellSelection cellSelection; + private FloatSelection floatSelection; + private boolean isAllHasWidget; + private boolean isAllHasHyperlink; + private String[] selectedPathArray; + private UIObserverListener observerListener = new UIObserverListener() { + @Override + public void doChange() { + if (elementCasePane == null || cellSelection == null) { + return; + } + if (setAuthorityStyle(NEW_VALUE)) { + elementCasePane.fireTargetModified(); + } + + } + }; + private ItemListener newValuelistener = new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || cellSelection == null) { + return; + } + if (setAuthorityStyle(NEW_VALUE)) { + valueEditor.setEnabled(newValue.isSelected()); + doAfterAuthority(); + } + } + }; + private ItemListener columnRowAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null) { + return; + } + boolean isDone = false; + if (selectionType == CellSelection.CHOOSE_COLUMN) { + isDone = setAuthorityColumn(); + } else { + isDone = setAuthorityRow(); + } + if (isDone) { + doAfterAuthority(); + } + } + }; + private ItemListener floatElementAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || floatSelection == null) { + return; + } + if (setLFloatAuthorityStyle()) { + doAfterAuthority(); + } + } + }; + private ItemListener cellRolesAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || cellSelection == null) { + return; + } + if (setAuthorityStyle(CELL)) { + doAfterAuthority(); + } + } + }; + private ItemListener widgetVisibleRoleAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || cellSelection == null) { + return; + } + if (setAuthorityStyle(WIDGET_VISIBLE)) { + doAfterAuthority(); + } + } + }; + private ItemListener widgetUsableAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || cellSelection == null) { + return; + } + + if (setAuthorityStyle(WIDGET_USABLE)) { + doAfterAuthority(); + } + } + }; + + public ElementCasePaneAuthorityEditPane(ElementCasePane elementCasePane) { + super(elementCasePane); + this.elementCasePane = elementCasePane; + initCheckBoxesState(); + initListener(); + } + + private void doAfterAuthority() { + elementCasePane.repaint(); + elementCasePane.fireTargetModified(); + RolesAlreadyEditedPane.getInstance().refreshDockingView(); + RolesAlreadyEditedPane.getInstance().setReportAndFSSelectedRoles(); + RolesAlreadyEditedPane.getInstance().repaint(); + checkCheckBoxes(); + } + + private boolean setAuthorityColumn() { + initSelectedPathArray(); + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { + return false; + } + if (selectedRoles == null) { + return false; + } + if (selectedPathArray == null) { + return false; + } + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + boolean isVisible = !gridColumnRowVisible.isSelected(); + for (int t = 0; t < selectedPathArray.length; t++) { + if (!isVisible) { + for (int col = cellSelection.getColumn(); col < cellSelection.getColumn() + cellSelection.getColumnSpan(); col++) { + elementCase.addColumnPrivilegeControl(col, selectedPathArray[t]); + } + } else { + for (int col = cellSelection.getColumn(); col < cellSelection.getColumn() + cellSelection.getColumnSpan(); col++) { + elementCase.removeColumnPrivilegeControl(col, selectedPathArray[t]); + } + } + } + + return true; + } + + private boolean setAuthorityRow() { + initSelectedPathArray(); + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { + return false; + } + if (selectedRoles == null) { + return false; + } + if (selectedPathArray == null) { + return false; + } + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + boolean isVisible = !gridColumnRowVisible.isSelected(); + for (int t = 0; t < selectedPathArray.length; t++) { + if (!isVisible) { + for (int row = cellSelection.getRow(); row < cellSelection.getRow() + cellSelection.getRowSpan(); row++) { + elementCase.addRowPrivilegeControl(row, selectedPathArray[t]); + } + } else { + for (int row = cellSelection.getRow(); row < cellSelection.getRow() + cellSelection.getRowSpan(); row++) { + elementCase.removeRowPrivilegeControl(row, selectedPathArray[t]); + } + } + } + + + return true; + } + + private boolean setLFloatAuthorityStyle() { + initSelectedPathArray(); + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { + return false; + } + if (selectedRoles == null) { + return false; + } + if (selectedPathArray == null) { + return false; + } + String name = floatSelection.getSelectedFloatName(); + TemplateElementCase ec = elementCasePane.getEditingElementCase(); + FloatElement fe = ec.getFloatElement(name); + for (int t = 0; t < selectedPathArray.length; t++) { + fe.changeAuthorityState(selectedPathArray[t], floatElementVisibleCheckBoxes.isSelected()); + } + + return true; + } + + private boolean setAuthorityStyle(int type) { + initSelectedPathArray(); + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { + return false; + } + if (selectedRoles == null) { + return false; + } + if (selectedPathArray == null) { + return false; + } + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + int cellRectangleCount = cellSelection.getCellRectangleCount(); + for (int t = 0; t < selectedPathArray.length; t++) { + + for (int rec = 0; rec < cellRectangleCount; rec++) { + Rectangle cellRectangle = cellSelection.getCellRectangle(rec); + // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 + for (int j = cellRectangle.height - 1; j >= 0; j--) { + for (int i = cellRectangle.width - 1; i >= 0; i--) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); + if (editCellElement == null) { + editCellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(editCellElement); + } else { + // 对于合并的格子,我们不多次计算的权限. + if (editCellElement.getColumn() != column + || editCellElement.getRow() != row) { + continue; + } + } + if (type == CELL) { + editCellElement.changeAuthorityState(selectedPathArray[t], cellElementVisibleCheckBoxes.isSelected()); + } else if (type == NEW_VALUE) { + editCellElement.changeNewValueAuthorityState(selectedPathArray[t], newValue.isSelected(), valueEditor.update()); + } else if (type == WIDGET_VISIBLE) { + Widget widget = editCellElement.getWidget(); + widget.changeVisibleAuthorityState(selectedPathArray[t], widgetVisible.isSelected()); + } else { + Widget widget = editCellElement.getWidget(); + widget.changeUsableAuthorityState(selectedPathArray[t], widgetAvailable.isSelected()); + } + + } + } + } + } + return true; + } + + /** + * @see AuthorityEditToolBarPane initSelectedPathArray + */ + private void initSelectedPathArray() { + TreePath[] selectionPaths = ReportAndFSManagePane.getInstance().getRoleTree().getCheckBoxTreeSelectionModel().getSelectionPaths(); + if (selectionPaths.length == 1) { + if (((ExpandMutableTreeNode) (selectionPaths[0].getLastPathComponent())).getChildCount() > 0) { + ExpandMutableTreeNode node = (ExpandMutableTreeNode) ((ExpandMutableTreeNode) (selectionPaths[0].getLastPathComponent())).getLastChild(); + System.out.printf(node.getUserObject().toString()); + selectedPathArray = new String[node.getChildCount()]; + for (int i = 0; i < node.getChildCount(); i++) { + ExpandMutableTreeNode n = (ExpandMutableTreeNode) node.getChildAt(i); + String nodeName = n.getUserObject().toString(); + selectedPathArray[i] = nodeName; + } + } else { + selectedPathArray = pathToString(selectionPaths); + } + } else { + selectedPathArray = pathToString(selectionPaths); + } + + } + + public static String[] pathToString(TreePath[] path) { + java.util.List roles = new ArrayList(); + if (path != null && path.length > 0) { + for (TreePath tempPath : path) { + String temp = tempPath.toString(); + boolean isTrue = temp.length() > 0 && temp.charAt(0) == '[' && temp.endsWith("]"); + if (isTrue) { + temp = temp.substring(1, temp.length() - 1); + String[] selectedRoles = temp.split("," + StringUtils.BLANK); + String role = selectedRoles[2].trim(); + roles.add(role); + } + + } + } + return roles.toArray(new String[0]); + } + + /** + * 选中的单元格的乐见状态以第一个单元格为齐 + */ + public void initCheckBoxesState() { + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + if (cellSelection == null) { + cellElementVisibleCheckBoxes.setSelected(true); + } else { + Rectangle cellRectangle = cellSelection.getCellRectangle(0); + DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellRectangle.x, cellRectangle.y); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(cellRectangle.x, cellRectangle.y); + } + boolean firstCellDoneaAuthority = cellElement.isDoneAuthority( + ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName()); + cellElementVisibleCheckBoxes.setSelected(!firstCellDoneaAuthority); + } + widgetAvailable.setEnabled(cellElementVisibleCheckBoxes.isSelected()); + widgetVisible.setEnabled(cellElementVisibleCheckBoxes.isSelected()); + } + + private void initListener() { + cellElementVisibleCheckBoxes.addItemListener(cellRolesAuthorityListener); + widgetVisible.addItemListener(widgetVisibleRoleAuthorityListener); + widgetAvailable.addItemListener(widgetUsableAuthorityListener); + floatElementVisibleCheckBoxes.addItemListener(floatElementAuthorityListener); + gridColumnRowVisible.addItemListener(columnRowAuthorityListener); + newValue.addItemListener(newValuelistener); + valueEditor.registerChangeListener(observerListener); + } + + private void removeListener() { + cellElementVisibleCheckBoxes.removeItemListener(cellRolesAuthorityListener); + widgetVisible.removeItemListener(widgetVisibleRoleAuthorityListener); + widgetAvailable.removeItemListener(widgetUsableAuthorityListener); + floatElementVisibleCheckBoxes.removeItemListener(floatElementAuthorityListener); + gridColumnRowVisible.removeItemListener(columnRowAuthorityListener); + newValue.removeItemListener(newValuelistener); + valueEditor.registerChangeListener(null); + } + + private void addHyperlinkListener() { + cellElementVisibleCheckBoxes.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (hyperlinkCheckBoxes != null) { + for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { + hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); + if (!cellElementVisibleCheckBoxes.isSelected()) { + hyperlinkCheckBoxes[i].setSelected(false); + } + } + } + } + }); + for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { + hyperlinkCheckBoxes[i].addItemListener(cellRolesAuthorityListener); + } + } + + /** + * 更新适合的类型 + */ + public void populateType() { + if (selectionType == CellSelection.NORMAL) { + type.setText(Inter.getLocText("FR-Designer_Cell")); + } else if (selectionType == CellSelection.CHOOSE_ROW) { + type.setText(Inter.getLocText("FR-Designer_Row")); + } else if (selectionType == CellSelection.CHOOSE_COLUMN) { + type.setText(Inter.getLocText("FR-Designer_Column")); + } else { + type.setText(Inter.getLocText("M_Insert-Float")); + } + } + + /** + * 名字 + */ + public void populateName() { + if (selectionType == CellSelection.NORMAL) { + name.setText(getCellSelectionName()); + } else if (selectionType == CellSelection.CHOOSE_ROW || selectionType == CellSelection.CHOOSE_COLUMN) { + name.setText(getCellColumnRowName()); + } else { + name.setText(getFloatSelectionName()); + } + } + + private String getCellSelectionName() { + String nameText = ""; + int count = cellSelection.getCellRectangleCount(); + for (int rect = 0; rect < count; rect++) { + nameText += ","; + Rectangle cellRectangle = cellSelection.getCellRectangle(rect); + ColumnRow beginCR = ColumnRow.valueOf(cellRectangle.x, cellRectangle.y); + nameText += beginCR.toString(); + if (cellRectangle.width * cellRectangle.height != 1) { + ColumnRow endCR = ColumnRow.valueOf(cellRectangle.width + cellRectangle.x - 1, cellRectangle.height + cellRectangle.y - 1); + nameText += ":" + endCR.toString(); + } + } + return nameText.substring(1); + } + + private String getCellColumnRowName() { + int count = cellSelection.getCellRectangleCount(); + String nameText = ""; + ColumnRow cr = ColumnRow.valueOf(cellSelection.getColumn(), cellSelection.getRow()); + if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && count == 1) { + if (cellSelection.getColumnSpan() == 1) { + nameText = cr.toString().substring(0, 1); + } else { + ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, + cellSelection.getRow() + cellSelection.getRowSpan() - 1); + nameText = cr.toString().substring(0, 1) + "-" + endCr.toString().substring(0, 1); + } + } else if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && count == 1) { + if (cellSelection.getRowSpan() == 1) { + nameText = cr.toString().substring(1); + } else { + ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, + cellSelection.getRow() + cellSelection.getRowSpan() - 1); + nameText = cr.toString().substring(1) + "-" + endCr.toString().substring(1); + } + } + return nameText; + } + + private String getFloatSelectionName() { + return floatSelection.getSelectedFloatName(); + } + + private void mutilRect(CellSelection cellSelection) { + isAllHasWidget = true; + isAllHasHyperlink = true; + int count = cellSelection.getCellRectangleCount(); + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + for (int rect = 0; rect < count; rect++) { + Rectangle cellRectangle = cellSelection.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); + } + if (cellElement.getCellWidgetAttr() == null) { + isAllHasWidget = false; + } + if (cellElement.getNameHyperlinkGroup() == null) { + isAllHasHyperlink = false; + } + } + } + } + } + + /** + * 更新适合的pane + * + * @return 返回Pane + */ + public JPanel populateCheckPane() { + checkPane.removeAll(); + if (selectionType == CellSelection.NORMAL) { + populateCellSelectionCheckPane(checkPane); + } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { + populateColumnRowCheckPane(checkPane); + } else if (selectionType == FLOAT_SELECTION) { + populateFloatSelectionCheckPane(checkPane); + } + checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); + return checkPane; + } + + private void populateColumnRowCheckPane(JPanel checkPane) { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{gridColumnRowVisible} + }; + double[] rowSize = {p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}}; + checkPane.add( + TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM) + , BorderLayout.WEST); + } + + private void populateFloatSelectionCheckPane(JPanel checkPane) { + checkPane.add(populateFloatElementCheckPane(), BorderLayout.WEST); + } + + private void populateCellSelectionCheckPane(JPanel checkPane) { + if (elementCasePane.isSelectedOneCell()) { + //只选中了一个单元格 + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellSelection.getColumn(), cellSelection.getRow()); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); + } + //单元格带控件 + if (cellElement.getCellWidgetAttr() != null) { + checkPane.add(populateWidgetCheckPane(), BorderLayout.WEST); + } else { + checkPane.add(populatCellCheckPane(), BorderLayout.WEST); + } + } else { + //批量选中单元格 + mutilRect(cellSelection); + if (!isAllHasWidget && !isAllHasHyperlink) { + checkPane.add(populateMutilCellCheckPane(), BorderLayout.WEST); + } else if (isAllHasWidget) { + checkPane.add(populateMutilWidgetCheckPane(), BorderLayout.WEST); + } + } + } + + /** + * 对单元格区域进行操作时的权限编辑页面 ,对应的角色的populate + */ + public void populateDetials() { + //做模式标记,此时鼠标焦点是在报表主体,为下一次退出权限编辑时做准备 + HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().setAuthorityMode(false); + TemplateElementCase templateElementCase = elementCasePane.getEditingElementCase(); + if (templateElementCase instanceof WorkSheet) { + ((WorkSheet) templateElementCase).setPaintSelection(true); + } + signelSelection(); + Selection selection = elementCasePane.getSelection(); + if (selection instanceof CellSelection) { + selectionType = CellSelection.NORMAL; + this.cellSelection = ((CellSelection) selection).clone(); + this.floatSelection = null; + judgeChooseCR(); + } else if (selection instanceof FloatSelection) { + selectionType = FLOAT_SELECTION; + cellSelection = null; + floatSelection = new FloatSelection(((FloatSelection) selection).getSelectedFloatName()); + } + populateType(); + populateName(); + populateCheckPane(); + checkCheckBoxes(); + } + + //判断是否选择的行列 + private void judgeChooseCR() { + if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && cellSelection.getCellRectangleCount() == 1) { + selectionType = CellSelection.CHOOSE_COLUMN; + } + if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && cellSelection.getCellRectangleCount() == 1) { + selectionType = CellSelection.CHOOSE_ROW; + } + } + + //实现单选 + private void signelSelection() { + JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (jTemplate.isJWorkBook()) { + //清工具栏 + JComponent component = DesignerContext.getDesignerFrame().getToolbarComponent(); + if (component instanceof AuthorityEditToolBarComponent) { + ((AuthorityEditToolBarComponent) component).removeSelection(); + } + //清参数面板 + jTemplate.removeParameterPaneSelection(); + } + } + + private JPanel populateFloatElementCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("M_Insert-Float"), SwingConstants.LEFT), floatElementVisibleCheckBoxes} + }; + double[] rowSize = {p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + private JPanel populateWidgetCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, + new Component[]{null, newValue}, + new Component[]{null, valueEditor}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, + new Component[]{null, widgetAvailable} + }; + double[] rowSize = {p, p, p, p, p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + private JPanel populateMutilWidgetCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, + new Component[]{null, widgetAvailable} + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + private JPanel populateMutilCellCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{cellElementVisibleCheckBoxes}, + }; + double[] rowSize = {p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + private JPanel populatCellCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{cellElementVisibleCheckBoxes}, + new Component[]{newValue}, + new Component[]{valueEditor} + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}, {1}, {1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + public TemplateCellElement getFirstCell() { + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + Rectangle cellRectangle = cellSelection.getCellRectangle(0); + // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 + TemplateCellElement firstCell = null; + for (int j = cellRectangle.height - 1; j >= 0; j--) { + for (int i = cellRectangle.width - 1; i >= 0; i--) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); + if (editCellElement != null) { + // 对于合并的格子,我们不多次计算的权限. + if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { + continue; + } + firstCell = editCellElement; + } + } + } + return firstCell; + } + + private void checkCheckBoxes() { + String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + removeListener(); + if (selectionType == CellSelection.NORMAL) { + checkCellSelectionCkeckboxes(selected); + } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { + checkColumnRowCheckBoxes(selected); + } else if (selectionType == FLOAT_SELECTION) { + checkFloatSelectionCkeckboxes(selected); + } + initListener(); + } + + private void checkCellSelectionCkeckboxes(String selected) { + TemplateCellElement firstCell = getFirstCell(); + if (firstCell == null) { + resetCellElementCheckBoxes(); + return; + } + cellElementVisibleCheckBoxes.setSelected(!firstCell.isDoneAuthority(selected)); + newValue.setEnabled(!firstCell.isDoneAuthority(selected)); + if (!firstCell.isDoneAuthority(selected)) { + newValue.setSelected(firstCell.isDoneNewValueAuthority(selected)); + if (newValue.isSelected()) { + valueEditor.setEnabled(true); + valueEditor.populate(firstCell.getCellPrivilegeControl().getNewValueMap().get(selected)); + } else { + valueEditor.setEnabled(false); + } + } else { + newValue.setSelected(false); + valueEditor.setEnabled(false); + } + populateWidgetButton(firstCell.getWidget(), selected, firstCell); + } + + private void populateWidgetButton(Widget widget, String selected, TemplateCellElement firstCell) { + if (widget != null) { + if (widget.isVisible()) { + widgetVisible.setSelected(!widget.isDoneVisibleAuthority(selected)); + widgetVisible.setEnabled(!firstCell.isDoneAuthority(selected)); + } else { + widgetVisible.setSelected(widget.isVisibleAuthority(selected)); + } + if (widget.isEnabled()) { + widgetAvailable.setSelected(!widget.isDoneUsableAuthority(selected)); + widgetAvailable.setEnabled(!widget.isDoneVisibleAuthority(selected)); + } else { + widgetAvailable.setSelected(widget.isUsableAuthority(selected)); + } + } + } + + private void resetCellElementCheckBoxes() { + cellElementVisibleCheckBoxes.setSelected(true); + widgetVisible.setSelected(true); + widgetVisible.setEnabled(true); + widgetAvailable.setSelected(true); + widgetAvailable.setEnabled(true); + newValue.setSelected(false); + valueEditor.setEnabled(false); + } + + private void checkColumnRowCheckBoxes(String selected) { + if (cellSelection == null) { + gridColumnRowVisible.setSelected(false); + return; + } + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + boolean isInside = selectionType == CellSelection.CHOOSE_COLUMN ? + elementCase.getColumnPrivilegeControl(cellSelection.getColumn()).checkInvisible(selected) : + elementCase.getRowPrivilegeControl(cellSelection.getRow()).checkInvisible(selected); + + gridColumnRowVisible.setSelected(isInside); + } + + private void checkFloatSelectionCkeckboxes(String selected) { + String name = floatSelection.getSelectedFloatName(); + TemplateElementCase ec = elementCasePane.getEditingElementCase(); + FloatElement fe = ec.getFloatElement(name); + floatElementVisibleCheckBoxes.setSelected(!fe.isDoneAuthority(selected)); + } + + private JPanel populateHyperlinkCheckPane(AbstractCellElement cellElement) { + NameJavaScriptGroup linkGroup = cellElement.getNameHyperlinkGroup(); + //超链接的个数+单元格可见的操作 + hyperlinkCheckBoxes = new UICheckBox[linkGroup.size()]; + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[hyperlinkCheckBoxes.length + 1][]; + if (linkGroup.size() == 1) { + components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; + components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; + + } else { + components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; + components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(linkGroup.getNameHyperlink(0).getName() + Inter.getLocText("FR-Designer_Visible"))}; + for (int i = 1; i < hyperlinkCheckBoxes.length; i++) { + components[i + 1] = new Component[]{null, hyperlinkCheckBoxes[i] = new UICheckBox(linkGroup.getNameHyperlink(i).getName() + Inter.getLocText("FR-Designer_Visible"))}; + } + } + for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { + hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); + } + addHyperlinkListener(); + double[] rowSize = new double[hyperlinkCheckBoxes.length + 1]; + int[][] rowCount = new int[hyperlinkCheckBoxes.length + 1][]; + for (int i = 0; i < hyperlinkCheckBoxes.length + 1; i++) { + rowSize[i] = p; + rowCount[i] = new int[]{1, 1}; + } + double[] columnSize = {p, f}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + + } + + private JPanel populateMutilHyperlinkCheckPane() { + //超链接的个数+单元格可见的操作 + hyperlinkCheckBoxes = new UICheckBox[1]; + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[2][]; + components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; + components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; + hyperlinkCheckBoxes[0].setEnabled(cellElementVisibleCheckBoxes.isSelected()); + addHyperlinkListener(); + double[] rowSize = {p, p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}, {1, 1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } +} \ No newline at end of file