protected override void Rename(string name)
 {
     StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
     page.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.Text = name;
     page.EditedObject.name = name;
     base.Rename(name);
 }
        /// <summary>
        /// Cette méthode est exécutée lorsqu'on sélectionne une Input Table sur la sidebar.
        /// Cette opération a pour but d'ouvrir une page pour la table selectionnée dans l'éditeur.
        /// </summary>
        /// <param name="sender">La table sélectionnée</param>
        protected void onSelectStructuredReportFromSidebar(object sender)
        {
            if (sender != null && sender is Kernel.Domain.StructuredReport)
            {
                Kernel.Domain.StructuredReport design = (Kernel.Domain.StructuredReport)sender;
                EditorItem<Kernel.Domain.StructuredReport> page = getStructuredReportEditor().getPage(design.name);
                if (page != null)
                {
                    page.fillObject();
                    getStructuredReportEditor().selectePage(page);
                }
                else if (design.oid != null && design.oid.HasValue)
                {
                    this.Open(design.oid.Value);
                }
                else
                {
                    page = getStructuredReportEditor().addOrSelectPage(design);
                    initializePageHandlers(page);
                    page.Title = design.name;

                    getStructuredReportEditor().ListChangeHandler.AddNew(design);
                }
                StructuredReportEditorItem pageOpen = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
                UpdateStatusBar();
            }
        }
        private void OnStructuredReportPropertiesSelectionColumnChange(object obj)
        {
            StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
            if (page == null) return;
            if (obj is StructuredReportColumn)
            {
                StructuredReportColumn column = (StructuredReportColumn)obj;

                if (column.type.Equals(StructuredReportColumn.Type.TARGET.ToString()))
                {
                    Target target = column.scope;
                    if (target.typeName.Equals(typeof(AttributeValue).Name, StringComparison.OrdinalIgnoreCase))
                    {
                        Kernel.Domain.AttributeValue value = GetStructuredReportService().ModelService.getAttributeValue(target.oid.Value, target.name);
                        column.SetValue(value);
                        page.getStructuredReportForm().StructuredReportPropertiesPanel.ColumnForms.Display(column);
                    }

                    if (target.typeName.Equals(typeof(Misp.Kernel.Domain.Attribute).Name, StringComparison.OrdinalIgnoreCase))
                    {
                        Misp.Kernel.Domain.Attribute value = GetStructuredReportService().ModelService.getAttributeByOid(target.oid.Value);
                        column.SetValue(value);
                        page.getStructuredReportForm().StructuredReportPropertiesPanel.ColumnForms.Display(column);
                    }
                    if (target.typeName.Equals(typeof(Entity).Name, StringComparison.OrdinalIgnoreCase))
                    {
                        Misp.Kernel.Domain.Entity value = GetStructuredReportService().ModelService.getEntityByOid(target.oid.Value);
                        column.SetValue(value);
                        page.getStructuredReportForm().StructuredReportPropertiesPanel.ColumnForms.Display(column);
                    }

                }

            }
        }
 protected void onGroupFieldChange()
 {
     StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
     string name = page.getStructuredReportForm().StructuredReportPropertiesPanel.groupField.textBox.Text;
     ((StructuredReportSideBar)SideBar).StructuredReportGroup.StructuredReportTreeview.updateStructuredReport(name, page.Title, true);
     OnChange();
 }
 private void OnStructuredReportPropertiesChange(object obj)
 {
     StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
     if (page == null) return;
     if (obj is bool && (bool)obj) BuildSheetTable();
     OnChange();
 }
 protected void DisplayActiveColumn()
 {
     StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
     if (page == null) return;
     Kernel.Ui.Office.Cell activeCell = page.getStructuredReportForm().SpreadSheet.getActiveCell();
     String activeCellName = activeCell != null ? activeCell.Name : null;
     page.getStructuredReportForm().StructuredReportPropertiesPanel.SelecteColumn(activeCell);
 }
 private void OnSetTableVisible(object item)
 {
     if (!(item is bool)) return;
     StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
     if (item is Kernel.Domain.TransformationTable) ((Kernel.Domain.TransformationTable)page.EditedObject).visibleInShortcut = (bool)item;
     if (item is Kernel.Domain.StructuredReport) ((Kernel.Domain.StructuredReport)page.EditedObject).visibleInShortcut = (bool)item;
     OnChange();
 }
 /// <summary>
 /// Cette méthode est exécutée lorsqu'on sélectionne une target sur la sidebar.
 /// Cette opération a pour but de rajouté la target sélectionnée au filtre de la table en édition,
 /// ou au scope des cellProperties correspondants à la sélection Excel.
 /// </summary>
 /// <param name="sender">La target sélectionné</param>
 protected void onSelectTargetFromSidebar(object sender)
 {
     if (sender != null && sender is Target)
     {
         StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
         if (page == null) return;
         page.getStructuredReportForm().StructuredReportPropertiesPanel.SetValue(sender);
     }
 }
 /// <summary>
 /// Cette méthode est exécutée lorsqu'on sélectionne une mesure sur la sidebar.
 /// Cette opération a pour but d'assigner la mesure sélectionnée 
 /// aux cellProperties correspondants à la sélection Excel.
 /// </summary>
 /// <param name="sender">La mesure sélectionnée</param>
 protected void onSelectMeasureFromSidebar(object sender)
 {
     if (sender != null && (sender is Measure || sender is CalculatedMeasure))
     {
         //Measure measure = (Measure)sender;
         StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
         if (page == null) return;
         page.getStructuredReportForm().StructuredReportPropertiesPanel.SetValue(sender);
     }
 }
        public override OperationState Rename()
        {
            if (base.Rename() != OperationState.CONTINUE)
                return OperationState.STOP;

            IsRenameOnDoubleClick = true;
            StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();

            return ValidateEditedNewName(page.EditedObject.name);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="oid"></param>
 /// <returns></returns>
 public override OperationState Open(Kernel.Domain.StructuredReport report)
 {
     StructuredReportEditorItem page = (StructuredReportEditorItem)getEditor().addOrSelectPage(report);
     UpdateStatusBar();
     initializePageHandlers(page);
     getEditor().ListChangeHandler.AddNew(report);
     page.getStructuredReportForm().StructuredReportPropertiesPanel.ColumnForms.ItemForm.PeriodicityService = GetStructuredReportService().PeriodicityService;
     DisplayActiveColumn();
     return OperationState.CONTINUE;
 }
 /// <summary>
 /// Cette methode permet de créer une nouvelle table.
 /// </summary>
 /// <returns>CONTINUE si la création du nouveau Model se termine avec succès. STOP sinon</returns>
 public override OperationState Create()
 {
     Kernel.Domain.StructuredReport report = GetNewStructuredReport();
     ((StructuredReportSideBar)SideBar).StructuredReportGroup.StructuredReportTreeview.AddStructuredReport(report);
     StructuredReportEditorItem page = (StructuredReportEditorItem)getEditor().addOrSelectPage(report);
     initializePageHandlers(page);
     page.Title = report.name;
     getEditor().ListChangeHandler.AddNew(report);
     page.getStructuredReportForm().StructuredReportPropertiesPanel.ColumnForms.ItemForm.PeriodicityService = GetStructuredReportService().PeriodicityService;
     DisplayActiveColumn();
     return OperationState.CONTINUE;
 }
 /// <summary>
 /// Cette methode est exécuté lorsqu'on édit le nom de la table active.
 /// Si l'utilisateur tappe sur la touche ENTER, le nouveau nom est validé.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 protected void onNameTextChange(object sender, KeyEventArgs args)
 {
     StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
     if (args.Key == Key.Escape)
     {
         page.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.Text = page.Title;
     }
     else if (args.Key == Key.Enter)
     {
         ValidateEditedNewName();
     }
 }
 private void OnVisibleInShortcutCheck(object sender, RoutedEventArgs e)
 {
     StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
     if (!page.getStructuredReportForm().StructuredReportPropertiesPanel.throwEvent) return;
     if (page.EditedObject is Kernel.Domain.StructuredReport)
     {
         ((Kernel.Domain.StructuredReport)page.EditedObject).visibleInShortcut = page.getStructuredReportForm().StructuredReportPropertiesPanel.visibleInShortcutCheckbox.IsChecked.Value;
     }
     else if (page.EditedObject is Kernel.Domain.TransformationTable)
     {
         ((Kernel.Domain.TransformationTable)page.EditedObject).visibleInShortcut = page.getStructuredReportForm().StructuredReportPropertiesPanel.visibleInShortcutCheckbox.IsChecked.Value;
     }
     OnChange();
 }
        protected void Mask(bool mask, string content = "Saving...")
        {
            StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
            if (page != null) page.getStructuredReportForm().Mask(mask);
            ApplicationManager.MainWindow.BusyBorder.Visibility = mask ? Visibility.Visible : Visibility.Hidden;
            if (mask)
            {
                ApplicationManager.MainWindow.LoadingProgressBar.Maximum = 100;
                ApplicationManager.MainWindow.LoadingProgressBar.Value = 0;
                ApplicationManager.MainWindow.LoadingLabel.Content = content;

                ApplicationManager.MainWindow.LoadingProgressBar.Visibility = Visibility.Visible;
                ApplicationManager.MainWindow.LoadingLabel.Visibility = Visibility.Visible;
                ApplicationManager.MainWindow.LoadingImage.Visibility = Visibility.Hidden;
            }
        }
        /// <summary>
        /// Sauve les objets en cours d'édition sur la page.
        /// </summary>
        /// <returns>
        /// OperationState.CONTINUE si l'opération a réussi
        /// OperationState.STOP sinon
        /// </returns>
        public override OperationState Save(EditorItem<Kernel.Domain.StructuredReport> page)
        {
            try
            {
                StructuredReportEditorItem currentPage = (StructuredReportEditorItem)page;
                if (base.Save(page) == OperationState.STOP) return OperationState.STOP;
            }
            catch (Exception)
            {
                DisplayError("Unable to save Structured Report", "Unable to save Excel file.");
                return OperationState.STOP;
            }
            Kernel.Domain.StructuredReport editedObject = page.EditedObject;

            return OperationState.CONTINUE;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected override void OnPageClosing(object sender, CancelEventArgs args)
        {
            base.OnPageClosing(sender, args);
            if (!args.Cancel)
            {
                StructuredReportEditorItem page = (StructuredReportEditorItem)sender;
                if (page.getStructuredReportForm().SpreadSheet != null && OperationState.STOP == page.getStructuredReportForm().SpreadSheet.Close())
                {
                    try
                    {
                        args.Cancel = true;
                    }
                    catch (Exception)
                    {
                        DisplayError("Unable to save Structured Report", "Unable to save Excel file.");

                    }
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected virtual OperationState ValidateEditedNewName(string newName = "")
        {
            StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
            Kernel.Domain.StructuredReport table = page.EditedObject;
            if (string.IsNullOrEmpty(newName))
                newName = page.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.Text.Trim();

            if (!validateName(newName)) return OperationState.STOP;

            if (string.IsNullOrEmpty(newName))
            {
                DisplayError("Empty Name", "The Structured Report name can't be mepty!");
                page.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.SelectAll();
                page.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.Focus();
                return OperationState.STOP;
            }

            bool found = false;
            if (GetStructuredReportService().getByName(newName) != null) found = true;

            foreach (StructuredReportEditorItem unInputTable in getStructuredReportEditor().getPages())
            {
                if ((found && newName != getStructuredReportEditor().getActivePage().Title) || (unInputTable != getStructuredReportEditor().getActivePage() && newName == unInputTable.Title))
                {
                    DisplayError("Duplicate Name", "There is another Structured Report named: " + newName);
                    page.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.Text = page.Title;
                    page.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.SelectAll();
                    page.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.Focus();
                    return OperationState.STOP;
                }
            }
            if (!IsRenameOnDoubleClick)
                if (table.name.ToUpper().Equals(newName.ToUpper())) return OperationState.CONTINUE;

            ((StructuredReportSideBar)SideBar).StructuredReportGroup.StructuredReportTreeview.updateStructuredReport(newName, table.name, false);
            table.name = newName;
            page.getStructuredReportForm().SpreadSheet.ChangeTitleBarCaption(newName);
            page.Title = newName;
            OnChange();
            return OperationState.CONTINUE;
        }
        private void updateRunProgress(AllocationRunInfo info)
        {
            StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();

            if (info == null || info.runEnded == true)
            {
                GetStructuredReportService().RunHandler -= updateRunProgress;
                page.IsModify = true;
                nextRunData = null;
                OnChange();
                Mask(false);
            }
            else
            {
                int rate = info.totalCellCount != 0 ? (Int32)(info.runedCellCount * 100 / info.totalCellCount) : 0;
                if (rate > 100) rate = 100;

                ApplicationManager.MainWindow.LoadingProgressBar.Maximum = info.totalCellCount;
                ApplicationManager.MainWindow.LoadingProgressBar.Value = info.runedCellCount;
                ApplicationManager.MainWindow.LoadingLabel.Content = "" + rate + " %";
            }
        }
        /// <summary>
        /// Initialisation des Handlers sur une nouvelle page.
        /// En plus des handlers de base, on initialise les handlers sur :
        /// - DesignerPropertiesPanel
        /// - 
        /// - SpreadSheet
        /// - 
        /// </summary>
        protected override void initializePageHandlers(EditorItem<Kernel.Domain.StructuredReport> page)
        {
            base.initializePageHandlers(page);
            StructuredReportEditorItem editorPage = (StructuredReportEditorItem)page;
            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.groupField.GroupService = GetStructuredReportService().GroupService;
            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.groupField.subjectType = SubjectTypeFound();
            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.KeyUp += onNameTextChange;
            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.NameTextBox.LostFocus += onNameTextLostFocus;
            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.groupField.Changed += onGroupFieldChange;
            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.OnAllocateEach += OnAllocateEach;
            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.OnSetTableVisible += OnSetTableVisible;

            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.visibleInShortcutCheckbox.Checked += OnVisibleInShortcutCheck;
            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.visibleInShortcutCheckbox.Unchecked += OnVisibleInShortcutCheck;

            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.Changed += OnStructuredReportPropertiesChange;
            editorPage.getStructuredReportForm().StructuredReportPropertiesPanel.selectionColumnChanged += OnStructuredReportPropertiesSelectionColumnChange;
            editorPage.getStructuredReportForm().SpreadSheet.SelectionChanged += OnSpreadSheetSelectionChanged;
            if (editorPage.getStructuredReportForm().AdministrationBar != null)
            {
                editorPage.getStructuredReportForm().AdministrationBar.Changed += OnChangeEventHandler;
            }
        }
        public virtual OperationState Run()
        {
            OperationState state = OperationState.CONTINUE;
            StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
            if (page == null) return state;
            nextRunData = null;
            String filePath = openSaveDialog();
            if (string.IsNullOrEmpty(filePath)) return state;

            StructuredReportRunData data = new StructuredReportRunData();
            data.filePath = filePath;
            if (page.EditedObject.oid.HasValue) data.oid = page.EditedObject.oid.Value;

            //if (page.IsModify)
            //{
            //    nextRunData = data;
            //    return Save(page);
            //}

            GetStructuredReportService().RunHandler += updateRunProgress;
            Mask(true, "Running...");
            GetStructuredReportService().Run(data);
            return state;
        }
 protected void BuildSheetTable()
 {
     StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
     if (page == null) return;
     page.getStructuredReportForm().BuildSheetTable();
 }
 private void OnAllocateEach(bool value)
 {
     StructuredReportEditorItem page = (StructuredReportEditorItem)getStructuredReportEditor().getActivePage();
     ((Kernel.Domain.TransformationTable)page.EditedObject).allocateEachLoop = value;
     OnChange();
 }