Esempio n. 1
0
void TableFrame::OnGroupVariables( wxCommandEvent& event)
{
    using namespace std;
    TableInterface* ti = table_base->GetTableInt();
    vector<int> sel_cols;
    table_base->GetSelectedCols(sel_cols);
    vector<cid_to_pos_pair> cid_to_disp(sel_cols.size());
    for (int i=0; i<sel_cols.size(); i++) {
        cid_to_pos_pair p;
        p.cid = sel_cols[i];
        p.pos = grid->GetColPos(sel_cols[i]);
        cid_to_disp[i] = p;
    }
    sort(cid_to_disp.begin(), cid_to_disp.end(), cid_to_pos_pair::less_than);
    for (int i=0; i<sel_cols.size(); i++) {
        sel_cols[i] = cid_to_disp[i].cid;
    }

    vector<wxString> names(sel_cols.size());
    for (int i=0; i<sel_cols.size(); ++i) names[i]=ti->GetColName(sel_cols[i]);
    wxString grp_nm = ti->SuggestGroupName(names);
    if (sel_cols.size() > 0) {
        if (ti->GetTimeSteps() == 1 && sel_cols.size() > 1) {
            if (table_state->GetNumDisallowTimelineChanges() > 0) {
                wxString msg = table_state->GetDisallowTimelineChangesMsg();
                wxMessageDialog dlg (this, msg, "Warning",
                                     wxOK | wxICON_INFORMATION);
                dlg.ShowModal();
                return;
            }
        }
        ti->GroupCols(sel_cols, grp_nm, sel_cols[0]);
    }
    table_base->DeselectAllCols();
    grid->Refresh();
    GdaFrame::GetGdaFrame()->UpdateToolbarAndMenus();
}
Esempio n. 2
0
void TableFrame::DisplayPopupMenu( wxGridEvent& ev )
{
    wxMenu* optMenu = wxXmlResource::Get()->
                      LoadMenu("ID_TABLE_VIEW_MENU_CONTEXT");

    TableInterface* ti = table_base->GetTableInt();
    SetEncodingCheckmarks(optMenu, ti->GetFontEncoding());
    popup_col = ev.GetCol();

    // Set Group item
    vector<int> sel_cols;
    table_base->GetSelectedCols(sel_cols);
    bool any_sel_time_variant = false;
    for (int i=0; i<sel_cols.size(); i++) {
        if (ti->IsColTimeVariant(sel_cols[i])) {
            any_sel_time_variant = true;
            break;
        }
    }
    bool all_sel_compatible = false;
    if (!any_sel_time_variant && sel_cols.size() > 1) {
        // check for compatible types
        all_sel_compatible = true;
        for (int i=0; i<sel_cols.size(); ++i) {
            if (!ti->IsColNumeric(sel_cols[i])) {
                all_sel_compatible = false;
                break;
            }
        }
    }
    if (any_sel_time_variant || !all_sel_compatible || sel_cols.size() <= 1 ||
            (ti->GetTimeSteps() > 1 && ti->GetTimeSteps() != sel_cols.size())) {
        optMenu->FindItem(XRCID("ID_TABLE_GROUP"))->Enable(false);
    } else {
        optMenu->FindItem(XRCID("ID_TABLE_GROUP"))->Enable(true);
    }

    // Set Ungroup item
    wxString ung_str("Ungroup Variable");
    bool ung_enable = false;
    if (popup_col >= 0 && ti->IsColTimeVariant(popup_col)) {
        wxString col_nm = ti->GetColName(popup_col);
        if (!col_nm.IsEmpty()) {
            ung_str = "Ungroup";
            ung_str << " \"" << col_nm << "\"";
            ung_enable = true;
        }
    }
    optMenu->FindItem(XRCID("ID_TABLE_UNGROUP"))->SetText(ung_str);
    optMenu->FindItem(XRCID("ID_TABLE_UNGROUP"))->Enable(ung_enable);

    // Set Rename item
    wxString rename_str("Rename Variable");
    if (popup_col != -1) {
        rename_str << " \"" << ti->GetColName(popup_col) << "\"";
    }
    optMenu->FindItem(XRCID("ID_TABLE_RENAME_VARIABLE"))->SetText(rename_str);
    bool enable_rename = false;
    if (popup_col!=-1) {
        if (ti->IsColTimeVariant(popup_col)) {
            enable_rename = true;
        } else {
            enable_rename = ti->PermitRenameSimpleCol();
        }
    }
    optMenu->FindItem(XRCID("ID_TABLE_RENAME_VARIABLE"))->Enable(enable_rename);

    PopupMenu(optMenu, ev.GetPosition());
}