private void createSectionToolbar(Section section, FormToolkit toolkit) { ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); ToolBar toolbar = toolBarManager.createControl(section); final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND); toolbar.setCursor(handCursor); // Cursor needs to be explicitly disposed toolbar.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (handCursor.isDisposed() == false) { handCursor.dispose(); } } }); fNewPluginAction = new NewPluginAction(); fNewFragmentAction = new NewFragmentAction(); toolBarManager.add(fNewPluginAction); toolBarManager.add(fNewFragmentAction); toolBarManager.update(true); section.setTextClient(toolbar); }
private void printPageDataSheet( HttpServletResponse response, VariablesSecureApp vars, String strC_BP_Group_ID, TableSQLData tableSQL) throws IOException, ServletException { if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); String strParamName = vars.getSessionValue(tabId + "|paramName"); boolean hasSearchCondition = false; vars.removeEditionData(tabId); hasSearchCondition = (tableSQL.hasInternalFilter() && ("").equals(strParamName)) || !(("").equals(strParamName) || ("%").equals(strParamName)); String strOffset = vars.getSessionValue(tabId + "|offset"); String selectedRow = "0"; if (!strC_BP_Group_ID.equals("")) { selectedRow = Integer.toString(getKeyPosition(vars, strC_BP_Group_ID, tableSQL)); } String[] discard = {"isNotFiltered", "isNotTest"}; if (hasSearchCondition) discard[0] = new String("isFiltered"); if (vars.getSessionValue("#ShowTest", "N").equals("Y")) discard[1] = new String("isTest"); XmlDocument xmlDocument = xmlEngine .readXmlTemplate( "org/openbravo/erpWindows/BusinessPartnerCategory/BusinessPartnerCategory_Relation", discard) .createXmlDocument(); boolean hasReadOnlyAccess = org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess( this, vars.getRole(), tabId); ToolBar toolbar = new ToolBar( this, true, vars.getLanguage(), "BusinessPartnerCategory", false, "document.frmMain.inpcBpGroupId", "grid", "..", "".equals("Y"), "BusinessPartnerCategory", strReplaceWith, false, false, false, false, !hasReadOnlyAccess); toolbar.setTabId(tabId); toolbar.setDeleteable(true && !hasReadOnlyAccess); toolbar.prepareRelationTemplate( "N".equals("Y"), hasSearchCondition, !vars.getSessionValue("#ShowTest", "N").equals("Y"), false, Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y")); xmlDocument.setParameter("toolbar", toolbar.toString()); StringBuffer orderByArray = new StringBuffer(); vars.setSessionValue(tabId + "|newOrder", "1"); String positions = vars.getSessionValue(tabId + "|orderbyPositions"); orderByArray.append("var orderByPositions = new Array(\n"); if (!positions.equals("")) { StringTokenizer tokens = new StringTokenizer(positions, ","); boolean firstOrder = true; while (tokens.hasMoreTokens()) { if (!firstOrder) orderByArray.append(",\n"); orderByArray.append("\"").append(tokens.nextToken()).append("\""); firstOrder = false; } } orderByArray.append(");\n"); String directions = vars.getSessionValue(tabId + "|orderbyDirections"); orderByArray.append("var orderByDirections = new Array(\n"); if (!positions.equals("")) { StringTokenizer tokens = new StringTokenizer(directions, ","); boolean firstOrder = true; while (tokens.hasMoreTokens()) { if (!firstOrder) orderByArray.append(",\n"); orderByArray.append("\"").append(tokens.nextToken()).append("\""); firstOrder = false; } } orderByArray.append(");\n"); // } xmlDocument.setParameter( "selectedColumn", "\nvar selectedRow = " + selectedRow + ";\n" + orderByArray.toString()); xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n"); xmlDocument.setParameter("windowId", windowId); xmlDocument.setParameter("KeyName", "cBpGroupId"); xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";"); xmlDocument.setParameter("theme", vars.getTheme()); // xmlDocument.setParameter("buttonReference", Utility.messageBD(this, "Reference", // vars.getLanguage())); try { WindowTabs tabs = new WindowTabs(this, vars, tabId, windowId, false); xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); xmlDocument.setParameter("childTabContainer", tabs.childTabs()); String hideBackButton = vars.getGlobalVariable("hideMenu", "#Hide_BackButton", ""); NavigationBar nav = new NavigationBar( this, vars.getLanguage(), "BusinessPartnerCategory_Relation.html", "BusinessPartnerCategory", "W", strReplaceWith, tabs.breadcrumb(), hideBackButton.equals("true")); xmlDocument.setParameter("navigationBar", nav.toString()); LeftTabsBar lBar = new LeftTabsBar( this, vars.getLanguage(), "BusinessPartnerCategory_Relation.html", strReplaceWith); xmlDocument.setParameter("leftTabs", lBar.relationTemplate()); } catch (Exception ex) { throw new ServletException(ex); } { OBError myMessage = vars.getMessage(tabId); vars.removeMessage(tabId); if (myMessage != null) { xmlDocument.setParameter("messageType", myMessage.getType()); xmlDocument.setParameter("messageTitle", myMessage.getTitle()); xmlDocument.setParameter("messageMessage", myMessage.getMessage()); } } xmlDocument.setParameter("grid", Utility.getContext(this, vars, "#RecordRange", windowId)); xmlDocument.setParameter("grid_Offset", strOffset); xmlDocument.setParameter("grid_SortCols", positions); xmlDocument.setParameter("grid_SortDirs", directions); xmlDocument.setParameter("grid_Default", selectedRow); response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); out.println(xmlDocument.print()); out.close(); }
private void printPageEdit( HttpServletResponse response, HttpServletRequest request, VariablesSecureApp vars, boolean boolNew, String strC_BP_Group_ID, TableSQLData tableSQL) throws IOException, ServletException { if (log4j.isDebugEnabled()) log4j.debug("Output: edit"); HashMap<String, String> usedButtonShortCuts; usedButtonShortCuts = new HashMap<String, String>(); String strOrderByFilter = vars.getSessionValue(tabId + "|orderby"); String orderClause = " C_BP_Group.Value"; if (strOrderByFilter == null || strOrderByFilter.equals("")) strOrderByFilter = orderClause; /*{ if (!strOrderByFilter.equals("") && !orderClause.equals("")) strOrderByFilter += ", "; strOrderByFilter += orderClause; }*/ String strCommand = null; BusinessPartnerCategoryData[] data = null; XmlDocument xmlDocument = null; FieldProvider dataField = vars.getEditionData(tabId); vars.removeEditionData(tabId); String strParamName = vars.getSessionValue(tabId + "|paramName"); boolean hasSearchCondition = false; hasSearchCondition = (tableSQL.hasInternalFilter() && ("").equals(strParamName)) || !(("").equals(strParamName) || ("%").equals(strParamName)); String strParamSessionDate = vars.getGlobalVariable( "inpParamSessionDate", Utility.getTransactionalDate(this, vars, windowId), ""); String buscador = ""; String[] discard = {"", "isNotTest"}; if (vars.getSessionValue("#ShowTest", "N").equals("Y")) discard[1] = new String("isTest"); if (dataField == null) { if (!boolNew) { discard[0] = new String("newDiscard"); data = BusinessPartnerCategoryData.selectEdit( this, vars.getSessionValue("#AD_SqlDateTimeFormat"), vars.getLanguage(), strC_BP_Group_ID, Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel)); if (!strC_BP_Group_ID.equals("") && (data == null || data.length == 0)) { response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION"); return; } refreshSessionEdit(vars, data); strCommand = "EDIT"; } if (boolNew || data == null || data.length == 0) { discard[0] = new String("editDiscard"); strCommand = "NEW"; data = new BusinessPartnerCategoryData[0]; } else { discard[0] = new String("newDiscard"); } } else { if (dataField.getField("cBpGroupId") == null || dataField.getField("cBpGroupId").equals("")) { discard[0] = new String("editDiscard"); strCommand = "NEW"; boolNew = true; } else { discard[0] = new String("newDiscard"); strCommand = "EDIT"; } } if (dataField == null) { if (boolNew || data == null || data.length == 0) { refreshSessionNew(vars); data = BusinessPartnerCategoryData.set( "", Utility.getDefault( this, vars, "AD_Client_ID", "@AD_CLIENT_ID@", "192", "", dataField), Utility.getDefault(this, vars, "AD_Org_ID", "@AD_Org_ID@", "192", "", dataField), "Y", Utility.getDefault(this, vars, "CreatedBy", "", "192", "", dataField), BusinessPartnerCategoryData.selectDef4966_0( this, Utility.getDefault(this, vars, "CreatedBy", "", "192", "", dataField)), Utility.getDefault(this, vars, "UpdatedBy", "", "192", "", dataField), BusinessPartnerCategoryData.selectDef4968_1( this, Utility.getDefault(this, vars, "UpdatedBy", "", "192", "", dataField)), Utility.getDefault(this, vars, "Value", "", "192", "", dataField), Utility.getDefault(this, vars, "Name", "", "192", "", dataField), Utility.getDefault(this, vars, "Description", "", "192", "", dataField), Utility.getDefault(this, vars, "IsDefault", "", "192", "N", dataField)); } } String currentOrg = (boolNew ? "" : (dataField != null ? dataField.getField("adOrgId") : data[0].getField("adOrgId"))); if (!currentOrg.equals("") && !currentOrg.startsWith("'")) currentOrg = "'" + currentOrg + "'"; String currentClient = (boolNew ? "" : (dataField != null ? dataField.getField("adClientId") : data[0].getField("adClientId"))); if (!currentClient.equals("") && !currentClient.startsWith("'")) currentClient = "'" + currentClient + "'"; boolean hasReadOnlyAccess = org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess( this, vars.getRole(), tabId); boolean editableTab = (!hasReadOnlyAccess && (currentOrg.equals("") || Utility.isElementInList( Utility.getContext(this, vars, "#User_Org", windowId, accesslevel), currentOrg)) && (currentClient.equals("") || Utility.isElementInList( Utility.getContext(this, vars, "#User_Client", windowId, accesslevel), currentClient))); if (editableTab) xmlDocument = xmlEngine .readXmlTemplate( "org/openbravo/erpWindows/BusinessPartnerCategory/BusinessPartnerCategory_Edition", discard) .createXmlDocument(); else xmlDocument = xmlEngine .readXmlTemplate( "org/openbravo/erpWindows/BusinessPartnerCategory/BusinessPartnerCategory_NonEditable", discard) .createXmlDocument(); xmlDocument.setParameter("tabId", tabId); ToolBar toolbar = new ToolBar( this, editableTab, vars.getLanguage(), "BusinessPartnerCategory", (strCommand.equals("NEW") || boolNew || (dataField == null && (data == null || data.length == 0))), "document.frmMain.inpcBpGroupId", "", "..", "".equals("Y"), "BusinessPartnerCategory", strReplaceWith, true, false, false, Utility.hasTabAttachments(this, vars, tabId, strC_BP_Group_ID), !hasReadOnlyAccess); toolbar.setTabId(tabId); toolbar.setDeleteable(true); toolbar.prepareEditionTemplate( "N".equals("Y"), hasSearchCondition, vars.getSessionValue("#ShowTest", "N").equals("Y"), "STD", Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y")); xmlDocument.setParameter("toolbar", toolbar.toString()); // set updated timestamp to manage locking mechanism if (!boolNew) { xmlDocument.setParameter( "updatedTimestamp", (dataField != null ? dataField.getField("updatedTimeStamp") : data[0].getField("updatedTimeStamp"))); } boolean concurrentSave = vars.getSessionValue(tabId + "|concurrentSave").equals("true"); if (concurrentSave) { // after concurrent save error, force autosave xmlDocument.setParameter("autosave", "Y"); } else { xmlDocument.setParameter("autosave", "N"); } vars.removeSessionValue(tabId + "|concurrentSave"); try { WindowTabs tabs = new WindowTabs(this, vars, tabId, windowId, true, (strCommand.equalsIgnoreCase("NEW"))); xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); // if (!strC_BP_Group_ID.equals("")) xmlDocument.setParameter("childTabContainer", // tabs.childTabs(false)); // else xmlDocument.setParameter("childTabContainer", tabs.childTabs(true)); xmlDocument.setParameter("childTabContainer", tabs.childTabs(false)); String hideBackButton = vars.getGlobalVariable("hideMenu", "#Hide_BackButton", ""); NavigationBar nav = new NavigationBar( this, vars.getLanguage(), "BusinessPartnerCategory_Relation.html", "BusinessPartnerCategory", "W", strReplaceWith, tabs.breadcrumb(), hideBackButton.equals("true"), !concurrentSave); xmlDocument.setParameter("navigationBar", nav.toString()); LeftTabsBar lBar = new LeftTabsBar( this, vars.getLanguage(), "BusinessPartnerCategory_Relation.html", strReplaceWith); xmlDocument.setParameter("leftTabs", lBar.editionTemplate(strCommand.equals("NEW"))); } catch (Exception ex) { throw new ServletException(ex); } xmlDocument.setParameter("commandType", strCommand); xmlDocument.setParameter("buscador", buscador); xmlDocument.setParameter("windowId", windowId); xmlDocument.setParameter("changed", ""); xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";"); xmlDocument.setParameter("theme", vars.getTheme()); final String strMappingName = Utility.getTabURL(tabId, "E", false); xmlDocument.setParameter("mappingName", strMappingName); xmlDocument.setParameter("confirmOnChanges", Utility.getJSConfirmOnChanges(vars, windowId)); // xmlDocument.setParameter("buttonReference", Utility.messageBD(this, "Reference", // vars.getLanguage())); xmlDocument.setParameter("paramSessionDate", strParamSessionDate); xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n"); OBError myMessage = vars.getMessage(tabId); vars.removeMessage(tabId); if (myMessage != null) { xmlDocument.setParameter("messageType", myMessage.getType()); xmlDocument.setParameter("messageTitle", myMessage.getTitle()); xmlDocument.setParameter("messageMessage", myMessage.getMessage()); } xmlDocument.setParameter("displayLogic", getDisplayLogicContext(vars, boolNew)); if (dataField == null) { xmlDocument.setData("structure1", data); } else { FieldProvider[] dataAux = new FieldProvider[1]; dataAux[0] = dataField; xmlDocument.setData("structure1", dataAux); } try { ComboTableData comboTableData = null; String userOrgList = ""; if (editableTab) userOrgList = Utility.getContext(this, vars, "#User_Org", windowId, accesslevel); // editable record else userOrgList = currentOrg; comboTableData = new ComboTableData( vars, this, "19", "AD_Org_ID", "", "", userOrgList, Utility.getContext(this, vars, "#User_Client", windowId), 0); Utility.fillSQLParameters( this, vars, (dataField == null ? data[0] : dataField), comboTableData, windowId, (dataField == null ? data[0].getField("adOrgId") : dataField.getField("adOrgId"))); xmlDocument.setData( "reportAD_Org_ID", "liststructure", comboTableData.select(!strCommand.equals("NEW"))); comboTableData = null; xmlDocument.setParameter("Created_Format", vars.getSessionValue("#AD_SqlDateTimeFormat")); xmlDocument.setParameter( "Created_Maxlength", Integer.toString(vars.getSessionValue("#AD_SqlDateTimeFormat").length())); xmlDocument.setParameter("Updated_Format", vars.getSessionValue("#AD_SqlDateTimeFormat")); xmlDocument.setParameter( "Updated_Maxlength", Integer.toString(vars.getSessionValue("#AD_SqlDateTimeFormat").length())); } catch (Exception ex) { ex.printStackTrace(); throw new ServletException(ex); } xmlDocument.setParameter("scriptOnLoad", getShortcutScript(usedButtonShortCuts)); final String refererURL = vars.getSessionValue(tabId + "|requestURL"); vars.removeSessionValue(tabId + "|requestURL"); if (!refererURL.equals("")) { final Boolean failedAutosave = (Boolean) vars.getSessionObject(tabId + "|failedAutosave"); vars.removeSessionValue(tabId + "|failedAutosave"); if (failedAutosave != null && failedAutosave) { final String jsFunction = "continueUserAction('" + refererURL + "');"; xmlDocument.setParameter("failedAutosave", jsFunction); } } if (strCommand.equalsIgnoreCase("NEW")) { vars.removeSessionValue(tabId + "|failedAutosave"); vars.removeSessionValue(strMappingName + "|hash"); } response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); out.println(xmlDocument.print()); out.close(); }
/** Initializes the GUI. */ private void initGUI() { try { getShell() .addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent evt) { shellWidgetDisposed(evt); } }); getShell() .addControlListener( new ControlAdapter() { public void controlResized(ControlEvent evt) { shellControlResized(evt); } }); getShell() .addControlListener( new ControlAdapter() { public void controlMoved(ControlEvent evt) { shellControlMoved(evt); } }); GridLayout thisLayout = new GridLayout(); this.setLayout(thisLayout); { GridData toolBarLData = new GridData(); toolBarLData.grabExcessHorizontalSpace = true; toolBarLData.horizontalAlignment = GridData.FILL; toolBar = new ToolBar(this, SWT.FLAT); toolBar.setLayoutData(toolBarLData); toolBar.setBackgroundImage(SWTResourceManager.getImage("images/ToolbarBackground.gif")); { newToolItem = new ToolItem(toolBar, SWT.NONE); newToolItem.setImage(SWTResourceManager.getImage("images/new.gif")); newToolItem.setToolTipText("New"); } { openToolItem = new ToolItem(toolBar, SWT.NONE); openToolItem.setToolTipText("Open"); openToolItem.setImage(SWTResourceManager.getImage("images/open.gif")); openToolItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { openToolItemWidgetSelected(evt); } }); } { saveToolItem = new ToolItem(toolBar, SWT.NONE); saveToolItem.setToolTipText("Save"); saveToolItem.setImage(SWTResourceManager.getImage("images/save.gif")); } } { clientArea = new Composite(this, SWT.NONE); GridData clientAreaLData = new GridData(); clientAreaLData.grabExcessHorizontalSpace = true; clientAreaLData.grabExcessVerticalSpace = true; clientAreaLData.horizontalAlignment = GridData.FILL; clientAreaLData.verticalAlignment = GridData.FILL; clientArea.setLayoutData(clientAreaLData); clientArea.setLayout(null); } { statusArea = new Composite(this, SWT.NONE); GridLayout statusAreaLayout = new GridLayout(); statusAreaLayout.makeColumnsEqualWidth = true; statusAreaLayout.horizontalSpacing = 0; statusAreaLayout.marginHeight = 0; statusAreaLayout.marginWidth = 0; statusAreaLayout.verticalSpacing = 0; statusAreaLayout.marginLeft = 3; statusAreaLayout.marginRight = 3; statusAreaLayout.marginTop = 3; statusAreaLayout.marginBottom = 3; statusArea.setLayout(statusAreaLayout); GridData statusAreaLData = new GridData(); statusAreaLData.horizontalAlignment = GridData.FILL; statusAreaLData.grabExcessHorizontalSpace = true; statusArea.setLayoutData(statusAreaLData); statusArea.setBackground(SWTResourceManager.getColor(239, 237, 224)); { statusText = new Label(statusArea, SWT.BORDER); statusText.setText(" Ready"); GridData txtStatusLData = new GridData(); txtStatusLData.horizontalAlignment = GridData.FILL; txtStatusLData.grabExcessHorizontalSpace = true; txtStatusLData.verticalIndent = 3; statusText.setLayoutData(txtStatusLData); } } thisLayout.verticalSpacing = 0; thisLayout.marginWidth = 0; thisLayout.marginHeight = 0; thisLayout.horizontalSpacing = 0; thisLayout.marginTop = 3; this.setSize(474, 312); { menu1 = new Menu(getShell(), SWT.BAR); getShell().setMenuBar(menu1); { fileMenuItem = new MenuItem(menu1, SWT.CASCADE); fileMenuItem.setText("&File"); { fileMenu = new Menu(fileMenuItem); { newFileMenuItem = new MenuItem(fileMenu, SWT.PUSH); newFileMenuItem.setText("&New"); newFileMenuItem.setImage(SWTResourceManager.getImage("images/new.gif")); } { openFileMenuItem = new MenuItem(fileMenu, SWT.PUSH); openFileMenuItem.setText("&Open"); openFileMenuItem.setImage(SWTResourceManager.getImage("images/open.gif")); openFileMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { openFileMenuItemWidgetSelected(evt); } }); } { closeFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE); closeFileMenuItem.setText("Close"); } { fileMenuSep1 = new MenuItem(fileMenu, SWT.SEPARATOR); } { saveFileMenuItem = new MenuItem(fileMenu, SWT.PUSH); saveFileMenuItem.setText("&Save"); saveFileMenuItem.setImage(SWTResourceManager.getImage("images/save.gif")); saveFileMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { saveFileMenuItemWidgetSelected(evt); } }); } { fileMenuSep2 = new MenuItem(fileMenu, SWT.SEPARATOR); } { exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE); exitMenuItem.setText("E&xit"); exitMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { exitMenuItemWidgetSelected(evt); } }); } fileMenuItem.setMenu(fileMenu); } } { helpMenuItem = new MenuItem(menu1, SWT.CASCADE); helpMenuItem.setText("&Help"); { helpMenu = new Menu(helpMenuItem); { aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE); aboutMenuItem.setText("&About"); aboutMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { aboutMenuItemWidgetSelected(evt); } }); } helpMenuItem.setMenu(helpMenu); } } } } catch (Exception e) { e.printStackTrace(); } }