/*___INFO__MARK_BEGIN__*/ /************************************************************************* * * The Contents of this file are made available subject to the terms of * the Sun Industry Standards Source License Version 1.2 * * Sun Microsystems Inc., March, 2001 * * * Sun Industry Standards Source License Version 1.2 * ================================================= * The contents of this file are subject to the Sun Industry Standards * Source License Version 1.2 (the "License"); You may not use this file * except in compliance with the License. You may obtain a copy of the * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html * * Software provided under this License is provided on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. * See the License for the specific provisions governing your rights and * obligations concerning the Software. * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * * Copyright: 2001 by Sun Microsystems, Inc. * * All Rights Reserved. * ************************************************************************/ /*___INFO__MARK_END__*/ #include #include #include #include #include #include #include #include #include "sge_usage.h" #include "cull.h" #include "gdi/sge_gdi.h" #include "sge_parse_num_par.h" #include "sge_complex_schedd.h" #include "sge_range.h" #include "sge_answer.h" #include "sge_job.h" #include "sge_qinstance.h" #include "sge_subordinate.h" #include "sge_centry.h" #include "sge_var.h" #include "sge_host.h" #include "sge_mailrec.h" #include "qmon_rmon.h" #include "qmon_quarks.h" #include "qmon_matrix.h" #include "qmon_load.h" #include "qmon_message.h" #include "qmon_util.h" static Widget CreateMatrixSimple(Widget parent, String name, ArgList arglist, Cardinal argcount); static Widget CreateMatrix(Widget parent, String name, ArgList arglist, Cardinal argcount); static void qmonMatrixLoseFocus(Widget w, XtPointer cld, XtPointer cad); static void qmonMatrixTraverse(Widget w, XtPointer cld, XtPointer cad); static void DeleteLines(Widget w, XtPointer cld, XtPointer cad); static void ColumnZeroNoEdit(Widget w, XtPointer cld, XtPointer cad); static void ColumnNoEdit(Widget w, XtPointer cld, XtPointer cad); static void set_2xN(Widget w, XtPointer address, XrmQuark type, Cardinal size); static void get_2xN(Widget w, XtPointer address, XrmQuark type, Cardinal size); static void set_CE_Type(Widget w, XtPointer address, XrmQuark type, Cardinal size); static Boolean getCE_TypeValues(lListElem *ep, const char **ce_entry); static Boolean setCE_TypeValues(lListElem *ep, char **ce_entry); static void set_CX_Type(Widget w, XtPointer address, XrmQuark type, Cardinal size); static void get_CX_Type(Widget w, XtPointer address, XrmQuark type, Cardinal size); static XmtWidgetType widgets[] = { { "Matrix_2xN", /* name */ NULL, /* class */ CreateMatrix, /* constructor */ set_2xN, /* procedure to set a value on widget */ get_2xN, /* procedure to get a value from widget */ False /* not a popup widget */ }, { "UserMatrix", /* name */ NULL, /* class */ CreateMatrix, /* constructor */ NULL, /* procedure to set a value on widget */ NULL, /* procedure to get a value from widget */ False /* not a popup widget */ }, { "CE_TypeMatrix", NULL, CreateMatrixSimple, set_CE_Type, NULL, False }, { "CX_TypeMatrix", NULL, CreateMatrix, set_CX_Type, get_CX_Type, False }, { "UU_TypeMatrix", NULL, CreateMatrixSimple, set_2xN, get_2xN, False }, { "LoadMatrix", NULL, CreateMatrixSimple, NULL, NULL, False } }; /*-------------------------------------------------------------------------*/ /* P U B L I C */ /*-------------------------------------------------------------------------*/ void QmonRegisterMatrixWidgets(void) { QmonInitQuarks(); /* initialize the quarks */ XmtRegisterWidgetTypes(widgets, XtNumber(widgets)); } /*-------------------------------------------------------------------------*/ /* P R I V A T E */ /*-------------------------------------------------------------------------*/ static Widget CreateMatrixSimple( Widget parent, String name, ArgList arglist, Cardinal argcount ) { Widget matrix; #ifndef TEXTCHILD_BUG Widget textChild; #endif matrix = XtCreateWidget(name, xbaeMatrixWidgetClass, parent, arglist, argcount); #ifndef TEXTCHILD_BUG XtVaGetValues(matrix, XmNtextField, &textChild, NULL); XtAddCallback(textChild, XmNlosingFocusCallback, qmonMatrixLoseFocus, (XtPointer) matrix); #endif /* ** register callback procedures */ XmtVaRegisterCallbackProcedures( "DeleteLines", DeleteLines, XtRWidget, "ColumnZeroNoEdit", ColumnZeroNoEdit, NULL, "ColumnNoEdit", ColumnNoEdit, NULL, NULL); return matrix; } /*-------------------------------------------------------------------------*/ static Widget CreateMatrix( Widget parent, String name, ArgList arglist, Cardinal argcount ) { Widget matrix; Widget textChild; matrix = XtCreateWidget(name, xbaeMatrixWidgetClass, parent, arglist, argcount); #ifndef TEXTCHILD_BUG XtVaGetValues(matrix, XmNtextField, &textChild, NULL); XtAddCallback(textChild, XmNlosingFocusCallback, qmonMatrixLoseFocus, (XtPointer) matrix); #endif XtAddCallback(matrix, XmNtraverseCellCallback, qmonMatrixTraverse, NULL); XtAddCallback(matrix, XmNselectCellCallback, qmonMatrixSelect, NULL); /* ** register callback procedures */ XmtVaRegisterCallbackProcedures( "DeleteLines", DeleteLines, XtRWidget, "ColumnZeroNoEdit", ColumnZeroNoEdit, NULL, "ColumnNoEdit", ColumnNoEdit, NULL, NULL); return matrix; } /*-------------------------------------------------------------------------*/ void qmonMatrixSelect(Widget w, XtPointer cld, XtPointer cad) { XbaeMatrixSelectCellCallbackStruct *cbs = (XbaeMatrixSelectCellCallbackStruct*) cad; int select_begin=0; int i; Widget* matrices = (Widget*) cld; DENTER(GUI_LAYER, "qmonMatrixSelect"); if (cbs->params && !strcmp(cbs->params[0], "begin")) { XbaeMatrixDeselectAll(w); while (matrices && *matrices) { XbaeMatrixDeselectAll(*matrices); matrices++; } XbaeMatrixSelectRow(w, cbs->row); } if (cbs->params && !strcmp(cbs->params[0], "end")) { while (matrices && *matrices) { XbaeMatrixDeselectAll(*matrices); matrices++; } select_begin = XbaeMatrixFirstSelectedRow(w); if (select_begin == -1) { XbaeMatrixSelectRow(w, cbs->row); DEXIT; return; } if (cbs->row < select_begin) { for (i=cbs->row; irow; i++) XbaeMatrixSelectRow(w, i); } } if (cbs->params && !strcmp(cbs->params[0], "toggle")) { if (XbaeMatrixIsRowSelected(w, cbs->row)) { DPRINTF(("XbaeMatrixDeselectRow\n")); XbaeMatrixDeselectRow(w, cbs->row); } else { XbaeMatrixSelectRow(w, cbs->row); DPRINTF(("XbaeMatrixSelectRow\n")); } } if (cbs->params && !strcmp(cbs->params[0], "editall")) { XbaeMatrixEditCell(w, cbs->row, cbs->column); } if (cbs->params && !strcmp(cbs->params[0], "edit") && cbs->column != 0) { XbaeMatrixEditCell(w, cbs->row, cbs->column); } DEXIT; } /*-------------------------------------------------------------------------*/ static void DeleteLines(Widget w, XtPointer cld, XtPointer cad) { Widget matrix = (Widget) cld; int rows; int i; int rows_to_delete = 0; int rows_old; int max_rows = 7; DENTER(GUI_LAYER, "DeleteLines"); if (!matrix) { DEXIT; return; } /* max_rows = XbaeMatrixVisibleRows(matrix); */ rows = rows_old = XbaeMatrixNumRows(matrix); for (i=0; icolumn == 0) cbs->doit = False; DEXIT; } /*-------------------------------------------------------------------------*/ static void ColumnNoEdit(Widget w, XtPointer cld, XtPointer cad) { XbaeMatrixEnterCellCallbackStruct *cbs = (XbaeMatrixEnterCellCallbackStruct*) cad; DENTER(GUI_LAYER, "ColumnNoEdit"); cbs->doit = False; DEXIT; } /*-------------------------------------------------------------------------*/ static void qmonMatrixTraverse(Widget w, XtPointer cld, XtPointer cad) { XbaeMatrixTraverseCellCallbackStruct *cbs = (XbaeMatrixTraverseCellCallbackStruct*) cad; static XrmQuark QDown = NULLQUARK; static XrmQuark QRight = NULLQUARK; static XrmQuark QUp = NULLQUARK; DENTER(GUI_LAYER, "qmonMatrixTraverse"); /* * Get the Quarks we care about */ if (QDown == NULLQUARK) { QDown = XrmStringToQuark("Down"); QUp = XrmStringToQuark("Up"); QRight = XrmStringToQuark("Right"); } /* ** if we are moving up don't jump to last row when we are in row 0 */ if ((cbs->qparam == QUp && cbs->row == 0)) { cbs->next_row = cbs->row; } /* * If we are moving down, and we are at the last row, add a new row * and traverse to it. */ if ((cbs->qparam == QDown && cbs->row == cbs->num_rows - 1) || (cbs->qparam == QRight && cbs->row == cbs->num_rows - 1 && cbs->column == cbs->num_columns)) { XbaeMatrixAddRows(w, cbs->num_rows, NULL, NULL, NULL, 1); cbs->next_row = cbs->num_rows; cbs->next_column = cbs->column; } DEXIT; } /*-------------------------------------------------------------------------*/ static void qmonMatrixLoseFocus(Widget w, XtPointer cld, XtPointer cad) { Widget matrix = (Widget) cld; XbaeMatrixCommitEdit(matrix, False); } /*-------------------------------------------------------------------------*/ static void set_2xN( Widget w, XtPointer address, XrmQuark type, Cardinal size ) { lList *lp = NULL; if (type != QmonQVA_Type && type != QmonQCE2_Type && type != QmonQHS_Type && type != QmonQMR_Type && type != QmonQPN_Type && type != QmonQAT_Type && type != QmonQSO_Type && type != QmonQUA_Type) { XmtWarningMsg("XmtDialogSetDialogValues", "XbaeMatrix", "Type Mismatch: Widget '%s':\n\tCan't set widget values" " from a resource of type '%s'", XtName(w), XrmQuarkToString(type)); return; } if (size == sizeof(lList*)) lp = *(lList**) address; else return; if (type == QmonQVA_Type) qmonSet2xN(w, lp, VA_variable, VA_value); else if ( type == QmonQCE2_Type ) qmonSet2xN(w, lp, CE_name, CE_stringval); else if ( type == QmonQHS_Type ) qmonSet2xN(w, lp, HS_name, HS_value); else if ( type == QmonQMR_Type ) qmonSet2xN(w, lp, MR_user, MR_host); else if ( type == QmonQPN_Type ) qmonSet2xN(w, lp, PN_path, PN_host); else if ( type == QmonQAT_Type ) qmonSet2xN(w, lp, AT_account, AT_cell); else if ( type == QmonQSO_Type ) qmonSet2xN(w, lp, SO_name, SO_threshold); else if ( type == QmonQUA_Type ) qmonSet2xN(w, lp, UA_name, UA_value); } /*-------------------------------------------------------------------------*/ static void get_2xN( Widget w, XtPointer address, XrmQuark type, Cardinal size ) { lList *lp = NULL; if (type != QmonQVA_Type && type != QmonQCE2_Type && type != QmonQHS_Type && type != QmonQMR_Type && type != QmonQPN_Type && type != QmonQAT_Type && type != QmonQSO_Type && type != QmonQUA_Type) { XmtWarningMsg("XmtDialogGetDialogValues", "XbaeMatrix", "Type Mismatch: Widget '%s':\n\tCan't get widget values" " from a resource of type '%s'", XtName(w), XrmQuarkToString(type)); return; } if (type == QmonQVA_Type) lp = qmonGet2xN(w, VA_Type, VA_variable, VA_value); else if ( type == QmonQCE2_Type ) lp = qmonGet2xN(w, CE_Type, CE_name, CE_stringval); else if ( type == QmonQHS_Type ) lp = qmonGet2xN(w, HS_Type, HS_name, HS_value); else if ( type == QmonQMR_Type ) lp = qmonGet2xN(w, MR_Type, MR_user, MR_host); else if ( type == QmonQPN_Type ) lp = qmonGet2xN(w, PN_Type, PN_path, PN_host); else if ( type == QmonQAT_Type ) lp = qmonGet2xN(w, AT_Type, AT_account, AT_cell); else if ( type == QmonQSO_Type ) lp = qmonGet2xN(w, SO_Type, SO_name, SO_threshold); else if ( type == QmonQUA_Type ) lp = qmonGet2xN(w, UA_Type, UA_name, UA_value); #if 0 /* * AA-2009-02-12 * leads to crash reverting memory leak fix in qmon_qaction.c */ if (*(lList**)address != NULL) { lFreeList((lList**)address); } #endif *(lList**)address = lp; } /*-------------------------------------------------------------------------*/ void qmonSetNxN(Widget w, lList *lp, int num_fields, ...) { lListElem *ep; int i, row; int max_rows; int val; double dval; char buf[128]; int *field; const char **col; va_list ap; DENTER(GUI_LAYER, "qmonSetNxN"); /* clear the area */ XtVaSetValues(w, XmNcells, NULL, NULL); if (!lp) { DEXIT; return; } field = malloc(num_fields*sizeof(int)); col = malloc(num_fields*sizeof(char *)); if (field == NULL || col == NULL) abort(); va_start(ap, num_fields); for(i=0; i