Ejemplo n.º 1
0
 /// <summary>
 /// Create new device template.
 /// </summary>
 public void NewTemplate()
 {
     try
     {
         //Ask save settings if device template is dirty.
         if (Device != null && Device.Dirty)
         {
             DialogResult ret = MessageBox.Show(ParentComponent, Gurux.DeviceSuite.Properties.Resources.SaveChangesQuestionTxt, Gurux.DeviceSuite.Properties.Resources.DeviceEditorTxt, MessageBoxButtons.YesNoCancel);
             if (ret == DialogResult.Cancel)
             {
                 return;
             }
             else if (ret == DialogResult.Yes)
             {
                 Save();
             }
         }
         GXWizardDlg dlg = new GXWizardDlg(null, Manufacturers, null);
         if (dlg.ShowDialog(ParentComponent) == DialogResult.Cancel)
         {
             return;
         }                
         Device = dlg.Target as GXDevice;
         Device.Save(Device.ProfilePath);                
         Device.Register();                
         ShowProperties(Device);                
         ParentComponent.CloseMenu.Enabled = true;
         ParentComponent.ExportMenu.Enabled = !System.Diagnostics.Debugger.IsAttached;
         ParentComponent.ImportMenu.Enabled = Device.AddIn.ImportFromDeviceEnabled;
         PropertyTree.SelectedNode = PropertyTree.Nodes[0];
         PropertyTree.Focus();                
         ValidateTasks();                
     }
     catch (Exception Ex)
     {
         GXCommon.ShowError(ParentComponent, Ex);
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }
Ejemplo n.º 2
0
 void EditObject(object target)
 {
     try
     {                                
         GXWizardDlg dlg = new GXWizardDlg(target, null, Device.AddIn);             
         if (dlg.ShowDialog(ParentComponent) == DialogResult.Cancel)
         {
             return;
         }
         this.ShowProperties(Device);
         NotifyDirty();            
     }
     catch (Exception Ex)
     {
         GXCommon.ShowError(ParentComponent, Ex);
     }
 }
Ejemplo n.º 3
0
 public void NewObject()
 {
     try
     {
         if (PropertyTree.SelectedNode == null ||
             PropertyTree.SelectedNode.Tag == null)
         {
             return;
         }
         GXProtocolAddIn AddIn = Device.AddIn;
         TreeNode parent = null;
         object source = PropertyTree.SelectedNode.Tag;
         //Add Category
         if (source is GXCategoryCollection)
         {
             GXCategoryCollection cats = source as GXCategoryCollection;
             GXCategory[] itemArray = AddIn.GetCategories(cats);
             if (itemArray.Length == 0)
             {
                 throw new Exception("No category types found.");
             }
             GXCategory cat = itemArray[0];
             parent = PropertyTree.SelectedNode;
             GXWizardDlg dlg = new GXWizardDlg(cat, cats.Parent, AddIn);
             if (dlg.ShowDialog(ParentComponent) == DialogResult.Cancel)
             {
                 return;
             }
             this.ShowProperties(Device);
             NotifyDirty();
         }
         //Add Table
         else if (source is GXTableCollection)
         {
             GXTableCollection tables = source as GXTableCollection;
             GXTable[] itemArray = AddIn.GetTables(tables);
             if (itemArray.Length == 0)
             {
                 throw new Exception("No table types found.");
             }
             GXTable table = itemArray[0];
             parent = PropertyTree.SelectedNode;
             GXWizardDlg dlg = new GXWizardDlg(table, tables.Parent, AddIn);
             if (dlg.ShowDialog(ParentComponent) == DialogResult.Cancel)
             {
                 return;
             }
             this.ShowProperties(Device);
             NotifyDirty();
         }
         //Add Property
         else if (source is GXProperty || source is GXCategory || source is GXTable)
         {
             GXCategory cat = null;
             GXTable table = null;
             object propertyParent = null;
             if (source is GXProperty)
             {
                 table = ((GXProperty)source).Table;
                 cat = ((GXProperty)source).Category;
                 if (table != null)
                 {
                     propertyParent = table;
                     parent = ObjectToTreeNode[table] as TreeNode;
                 }
                 else if (cat != null)
                 {
                     propertyParent = cat;
                     parent = ObjectToTreeNode[cat] as TreeNode;
                 }
             }
             else if (source is GXCategory)
             {
                 propertyParent = cat = (GXCategory)source;
                 parent = ObjectToTreeNode[cat] as TreeNode;
             }
             else if (source is GXTable)
             {
                 propertyParent = table = (GXTable)source;
                 parent = ObjectToTreeNode[table] as TreeNode;
             }
             else
             {
                 //Shouldn't get here
                 throw new Exception("Unknown error while adding property.");
             }
             GXProperty[] itemArray = AddIn.GetProperties(source);
             if (itemArray.Length == 0)
             {
                 throw new Exception("No property types found.");
             }
             GXProperty prop = itemArray[0];
             GXWizardDlg dlg = new GXWizardDlg(prop, propertyParent, AddIn);
             if (dlg.ShowDialog(ParentComponent) == DialogResult.Cancel)
             {
                 return;
             }
             this.ShowProperties(Device);
             NotifyDirty();
         }
         else
         {
             throw new Exception("Unknown type to add.");
         }
         parent.Expand();
         ValidateTasks();
     }
     catch (Exception Ex)
     {
         GXCommon.ShowError(ParentComponent, Ex);
     }
 }