Пример #1
0
        /// <summary>
        /// Import d'un service
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="e">The <see cref="Microsoft.VisualStudio.Modeling.Diagrams.DiagramDragEventArgs"/> instance containing the event data.</param>
        internal static void OnDragDropOnLayer(NodeShape shape, DiagramDragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                string txt = (string)e.Data.GetData(DataFormats.Text);
                using (
                    Transaction transaction =
                        shape.ModelElement.Store.TransactionManager.BeginTransaction("Import interface"))
                {
                    // On ne veut pas que les assistants soient appelés
                    shape.ModelElement.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.
                    ContextInfo[StrategyManager.IgnoreStrategyWizards] = true;

                    IImportInterfaceHelper importer = ServiceLocator.Instance.GetService <IImportInterfaceHelper>();
                    if (importer == null)
                    {
                        return;
                    }
                    if (importer.ImportOperations(shape.ModelElement as SoftwareLayer, null, txt))
                    {
                        shape.RebuildShape();
                        transaction.Commit();
                    }
                }

                using (
                    Transaction transaction =
                        shape.ModelElement.Store.TransactionManager.BeginTransaction("Arrange ports"))
                {
                    LayerHelper.ArrangePorts(shape, typeof(ServiceContractShape));
                    transaction.Commit();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Import d'un service
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="e">The <see cref="Microsoft.VisualStudio.Modeling.Diagrams.DiagramDragEventArgs"/> instance containing the event data.</param>
        /// <returns></returns>
        internal static bool OnDragDropOnPackage(NodeShape shape, DiagramDragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                string txt = (string)e.Data.GetData(DataFormats.Text);
                using (
                    Transaction transaction =
                        shape.ModelElement.Store.TransactionManager.BeginTransaction("Import entity"))
                {
                    // On ne veut pas que les assistants soient appelés
                    shape.ModelElement.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.
                    ContextInfo[StrategyManager.IgnoreStrategyWizards] = true;

                    IImportEntityHelper importer = ServiceLocator.Instance.GetService <IImportEntityHelper>();
                    if (importer == null)
                    {
                        return(false);
                    }
                    if (importer.ImportProperties(shape.ModelElement as Package, null, txt))
                    {
                        shape.RebuildShape();
                        transaction.Commit();
                    }
                }

                return(true);
            }
            return(false);
        }
Пример #3
0
        /// <summary>
        /// Drop d'un modèle à partir du repository tree
        /// </summary>
        /// <param name="e">The diagram drag event arguments.</param>
        public override void OnDragDrop(DiagramDragEventArgs e)
        {
            base.OnDragDrop(e);

            if (e.Data.GetDataPresent(typeof(RepositoryTreeControl.RepositoryDataDragDrop)))
            {
                RepositoryTreeControl.RepositoryDataDragDrop data = (RepositoryTreeControl.RepositoryDataDragDrop)e.Data.GetData(typeof(RepositoryTreeControl.RepositoryDataDragDrop));
                if (data != null && this.ModelElement is CandleModel)
                {
                    CandleModel model = ((CandleModel)this.ModelElement);

                    using (Transaction transaction = model.Store.TransactionManager.BeginTransaction("Drop a model"))
                    {
                        // On ne le met pas si il y est dèjà
                        if (model.Id == data.MetaData.Id)
                        {
                            ServiceLocator.Instance.IDEHelper.ShowMessage("You can not drag the current model.");
                            return;
                        }
                        if (model.FindExternalComponent(data.MetaData.Id) != null)
                        {
                            ServiceLocator.Instance.IDEHelper.ShowMessage("This model already exists in the designer.");
                            return;
                        }

                        ExternalComponent system = data.MetaData.CreateComponent(model);
                        transaction.Commit();
                    }
                }
            }
        }
Пример #4
0
        private bool IsAcceptableDropItem(DiagramDragEventArgs diagramDragEventArgs)
        {
            IsDropping = (diagramDragEventArgs.Data.GetData("Text") is string filename && File.Exists(filename)) ||
                         (diagramDragEventArgs.Data.GetData("FileDrop") is string[] filenames && filenames.All(File.Exists));

            return(IsDropping);
        }
Пример #5
0
 /// <summary>
 /// Drag d'élément d'un projet sur un layer
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="e">The <see cref="Microsoft.VisualStudio.Modeling.Diagrams.DiagramDragEventArgs"/> instance containing the event data.</param>
 internal static void OnDragOverLayer(NodeShape shape, DiagramDragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.Text) &&
         (shape.ModelElement is InterfaceLayer || shape.ModelElement is Layer))
     {
         string txt = (string)e.Data.GetData(DataFormats.Text);
         if (File.Exists(txt))
         {
             FileCodeModel fcm = ServiceLocator.Instance.ShellHelper.GetFileCodeModel(txt);
             if (fcm != null)
             {
                 foreach (CodeElement cn in fcm.CodeElements)
                 {
                     if (cn is CodeNamespace)
                     {
                         foreach (CodeElement ci in ((CodeNamespace)cn).Members)
                         {
                             if (ci is CodeInterface && shape.ModelElement is InterfaceLayer ||
                                 // Une interface seulement sur la couche interface
                                 ci is CodeClass) // Une classe n'importe ou
                             {
                                 e.Effect = DragDropEffects.Link;
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
        /// <summary>
        /// Check for column reordering
        /// </summary>
        public override void OnDragOver(DiagramDragEventArgs e)
        {
            // I want to handle this in subfield-specific events using
            // enter events only. However, the list compartment doesn't
            // support enter/leave/hover events (these extensions were
            // added to the core elements, but I can't get access to the
            // correct base types here), so we have to reprocess on every
            // mouse move.
            IDataObject data;
            Column      targetColumn;
            Column      sourceColumn;
            Table       table;

            if (null != (data = e.Data) &&
                data.GetDataPresent(typeof(Column)) &&
                null != (targetColumn = ResolveColumn(e.HitDiagramItem)) &&
                null != (sourceColumn = data.GetData(typeof(Column)) as Column) &&
                targetColumn != sourceColumn &&
                (table = targetColumn.Table) == sourceColumn.Table)
            {
                e.Effect  = DragDropEffects.Move;
                e.Handled = true;
            }
            base.OnDragOver(e);
        }
Пример #7
0
        public override void OnDragOver(DiagramDragEventArgs e)
        {
            if (e.Data.GetFormats().Contains("VSToolboxUniqueID"))
            {
                var model    = this.Diagram.ModelElement as nHydrateModel;
                var typeName = (e.Data.GetData("VSToolboxUniqueID") as MemoryStream).GetString().Replace("\0", string.Empty);
                if (typeName == "nHydrate.DslPackage.ViewToolboxItem")
                {
                    if ((model.DiagramVisibility & VisibilityTypeConstants.View) != VisibilityTypeConstants.View)
                    {
                        e.Effect = DragDropEffects.None;
                        return;
                    }
                }
                else if (typeName == "nHydrate.DslPackage.StoredProcedureToolboxItem")
                {
                    if ((model.DiagramVisibility & VisibilityTypeConstants.StoredProcedure) != VisibilityTypeConstants.StoredProcedure)
                    {
                        e.Effect = DragDropEffects.None;
                        return;
                    }
                }
                else if (typeName == "nHydrate.DslPackage.FunctionToolboxItem")
                {
                    if ((model.DiagramVisibility & VisibilityTypeConstants.Function) != VisibilityTypeConstants.Function)
                    {
                        e.Effect = DragDropEffects.None;
                        return;
                    }
                }
            }

            base.OnDragOver(e);
        }
Пример #8
0
 /// <summary>
 /// Called when [drag over package].
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="e">The <see cref="Microsoft.VisualStudio.Modeling.Diagrams.DiagramDragEventArgs"/> instance containing the event data.</param>
 /// <returns></returns>
 internal static bool OnDragOverPackage(NodeShape shape, DiagramDragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.Text) && (shape.ModelElement is Package))
     {
         string txt = (string)e.Data.GetData(DataFormats.Text);
         if (File.Exists(txt))
         {
             // Il faut que ce soit une interface
             FileCodeModel fcm = ServiceLocator.Instance.ShellHelper.GetFileCodeModel(txt);
             if (fcm != null)
             {
                 foreach (CodeElement cn in fcm.CodeElements)
                 {
                     if (cn is CodeNamespace)
                     {
                         foreach (CodeElement ci in ((CodeNamespace)cn).Members)
                         {
                             if (ci is CodeClass && shape.ModelElement is Package)
                             {
                                 e.Effect = DragDropEffects.Link;
                                 return(true);
                             }
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
Пример #9
0
 /// <summary>
 /// Drag drop d'un projet
 /// </summary>
 /// <param name="e">The diagram drag event arguments.</param>
 public override void OnDragOver(DiagramDragEventArgs e)
 {
     base.OnDragOver(e);
     if (e.Data.GetDataPresent("CF_VSREFPROJECTS"))
     {
         e.Effect = DragDropEffects.Link;
     }
 }
Пример #10
0
 /// <summary>
 /// Alerts listeners when the shape is dragged over its bounds.
 /// </summary>
 /// <param name="e">The diagram drag event arguments.</param>
 public override void OnDragOver(DiagramDragEventArgs e)
 {
     base.OnDragOver(e);
     if (e.Data.GetDataPresent(typeof(RepositoryTreeControl.RepositoryDataDragDrop)) &&
         this.ModelElement is CandleModel && ((CandleModel)this.ModelElement).Component != null)
     {
         e.Effect = System.Windows.Forms.DragDropEffects.Copy;
     }
 }
Пример #11
0
        /// <summary>
        /// Used for dropping data originating outside of VStudio
        /// </summary>
        /// <param name="diagramDragEventArgs"></param>
        /// <returns></returns>
        private bool IsAcceptableDropItem(DiagramDragEventArgs diagramDragEventArgs)
        {
            IsDroppingExternal = (diagramDragEventArgs.Data.GetData("Text") is string filenames1 &&
                                  filenames1.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries) is string[] filenames2 &&
                                  filenames2.All(File.Exists)) ||
                                 (diagramDragEventArgs.Data.GetData("FileDrop") is string[] filenames3 && filenames3.All(File.Exists));

            return(IsDroppingExternal);
        }
Пример #12
0
 /// <summary>
 /// Alerts listeners when the shape is dragged and dropped.
 /// </summary>
 /// <param name="e">The diagram drag event arguments.</param>
 public override void OnDragDrop(DiagramDragEventArgs e)
 {
     base.OnDragDrop(e);
     if (e.Data.GetDataPresent("CF_VSREFPROJECTS"))
     {
         SoftwareComponent component = ModelElement as SoftwareComponent;
         ImportProjectHelper.Import(e.Data.GetData("CF_VSREFPROJECTS"), component, null);
     }
 }
Пример #13
0
        public override void OnDragOver(DiagramDragEventArgs diagramDragEventArgs)
        {
            base.OnDragOver(diagramDragEventArgs);

            if (diagramDragEventArgs.Effect == DragDropEffects.None && IsAcceptableDropItem(diagramDragEventArgs))
            {
                diagramDragEventArgs.Effect = DragDropEffects.Copy;
            }
        }
 /// <summary>
 /// Called when the user drags over parts of the diagram.
 /// </summary>
 /// <param name="e"></param>
 public override void OnDragOver(DiagramDragEventArgs e)
 {
     base.OnDragOver(e);
     if (e.Control && // user is pressing CTRL key.
         e.Effect == System.Windows.Forms.DragDropEffects.None &&
         IsAcceptableDropItem(e))
     {
         // Set the cursor to show [+]:
         e.Effect = System.Windows.Forms.DragDropEffects.Copy;
     }
 }
Пример #15
0
 /// <summary>
 /// Alerts listeners when the shape is dragged and dropped.
 /// </summary>
 /// <param name="e">The diagram drag event arguments.</param>
 public override void OnDragDrop(DiagramDragEventArgs e)
 {
     base.OnDragDrop(e);
     if (e.Data.GetDataPresent("CF_VSREFPROJECTS"))
     {
         LayerPackage package = ModelElement as LayerPackage;
         if (package != null)
         {
             ImportProjectHelper.Import(e.Data.GetData("CF_VSREFPROJECTS"), package.Component, package);
         }
     }
 }
Пример #16
0
 /// <summary>
 /// Alerts listeners when the shape is dragged over its bounds.
 /// </summary>
 /// <param name="e">The diagram drag event arguments.</param>
 public override void OnDragOver(DiagramDragEventArgs e)
 {
     base.OnDragOver(e);
     if (e.Data.GetDataPresent(DataFormats.Text))
     {
         string txt = (string)e.Data.GetData(DataFormats.Text);
         if (File.Exists(txt))
         {
             e.Effect = DragDropEffects.Link;
         }
     }
 }
 /// <summary>
 /// Called when the user lets go of the mouse button after dragging.
 /// </summary>
 /// <param name="e"></param>
 public override void OnDragDrop(DiagramDragEventArgs e)
 {
     if (e.Control && // User pressing CTRL key.
         IsAcceptableDropItem(e))
     {
         ProcessDragDropItem(e);
     }
     else
     {
         base.OnDragDrop(e);
     }
 }
        /// <summary>
        /// Reorder columns if a column is dropped on a different column
        /// in the same table.
        /// </summary>
        public override void OnDragDrop(DiagramDragEventArgs e)
        {
            IDataObject data;
            Column      targetColumn;
            Column      sourceColumn;

            if (null != (data = e.Data) &&
                data.GetDataPresent(typeof(Column)) &&
                null != (targetColumn = ResolveColumn(e.HitDiagramItem)) &&
                null != (sourceColumn = data.GetData(typeof(Column)) as Column))
            {
                e.Handled = Table.CustomReorderColumns(new Column[] { sourceColumn }, targetColumn);
            }
            base.OnDragDrop(e);
        }
Пример #19
0
        /// <summary>
        /// Alerts listeners when the shape is dragged and dropped.
        /// </summary>
        /// <param name="e">The diagram drag event arguments.</param>
        public override void OnDragDrop(DiagramDragEventArgs e)
        {
            base.OnDragDrop(e);

            bool canArrangeShapes = NestedChildShapes.Count == 0;

            if (DragDropHelper.OnDragDropOnPackage(this, e))
            {
                if (canArrangeShapes)
                {
                    ArrangeShapes();
                }
                return;
            }

            if (e.Data.GetDataPresent(ServerExplorerHelper.DataSourceReferenceFormat))
            {
                if (ServerExplorerHelper.ContainsTable(e.Data))
                {
                    if (ServerExplorerHelper.ImportTables(ModelElement as Package,
                                                          new ServiceProvider(
                                                              (IServiceProvider)
                                                              ModelingPackage.GetGlobalService(typeof(DTE))),
                                                          e.Data))
                    {
                        if (canArrangeShapes)
                        {
                            ArrangeShapes();
                        }
                    }
                }
                if (ServerExplorerHelper.ContainsStoredProcedures(e.Data))
                {
                    if (ServerExplorerHelper.ImportStoredProcedures(ModelElement as Package,
                                                                    new ServiceProvider(
                                                                        (IServiceProvider)
                                                                        ModelingPackage.GetGlobalService(typeof(DTE))),
                                                                    e.Data))
                    {
                        if (canArrangeShapes)
                        {
                            ArrangeShapes();
                        }
                    }
                }
            }
        }
        private bool IsAcceptableDropItem(DiagramDragEventArgs e)
        {
            if (e.Prototype == null)
            {
                return(false);
            }
            IMergeElements mergeTarget = (IMergeElements)this.ModelElement;

            foreach (ProtoElement proto in e.Prototype.RootProtoElements)
            {
                if (mergeTarget.CanMerge(proto, e.Prototype))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #21
0
        /// <summary>
        /// Alerts listeners when the shape is dragged over its bounds.
        /// </summary>
        /// <param name="e">The diagram drag event arguments.</param>
        public override void OnDragOver(DiagramDragEventArgs e)
        {
            base.OnDragOver(e);

            if (DragDropHelper.OnDragOverPackage(this, e))
            {
                return;
            }

            if (e.Data.GetDataPresent(ServerExplorerHelper.DataSourceReferenceFormat))
            {
                if (ServerExplorerHelper.ContainsTable(e.Data) || ServerExplorerHelper.ContainsStoredProcedures(e.Data))
                {
                    e.Effect = DragDropEffects.Copy;
                }
            }
        }
Пример #22
0
        public override void OnDragDrop(DiagramDragEventArgs diagramDragEventArgs)
        {
            base.OnDragDrop(diagramDragEventArgs);

            if (IsDropping)
            {
                string[] missingFiles = null;

                if (diagramDragEventArgs.Data.GetData("Text") is string filename)
                {
                    if (!File.Exists(filename))
                    {
                        missingFiles = new[] { filename }
                    }
                    ;
                    else
                    {
                        FileDropHelper.HandleDrop(Store, filename);
                    }
                }
                else if (diagramDragEventArgs.Data.GetData("FileDrop") is string[] filenames)
                {
                    string[] existingFiles = filenames.Where(File.Exists).ToArray();
                    FileDropHelper.HandleMultiDrop(Store, existingFiles);
                    missingFiles = filenames.Except(existingFiles).ToArray();
                }
                else
                {
                    base.OnDragDrop(diagramDragEventArgs);
                }

                if (missingFiles != null && missingFiles.Any())
                {
                    if (missingFiles.Length > 1)
                    {
                        missingFiles[missingFiles.Length - 1] = "and " + missingFiles[missingFiles.Length - 1];
                    }
                    ErrorDisplay.Show($"Can't find files {string.Join(", ", missingFiles)}");
                }
            }

            IsDropping = false;
        }
        private void ProcessDragDropItem(DiagramDragEventArgs e)
        {
            // Utility class:
            DesignSurfaceElementOperations op = this.ElementOperations;

            ShapeElement pasteTarget = this;

            // Check whether what's in the paste buffer is acceptable on the target.
            if (op.CanMerge(pasteTarget.ModelElement, e.Data))
            {
                // Although op.Merge would be a no-op if CanMerge failed, we check CanMerge first
                // so that we don't create an empty transaction (after which Undo would be no-op).
                using (Transaction t = this.Store.TransactionManager.BeginTransaction("paste"))
                {
                    PointD place = e.MousePosition;
                    op.Merge(pasteTarget, e.Data, PointD.ToPointF(place));
                    t.Commit();
                }
            }
        }
Пример #24
0
        protected override void OnDropSelectedShapes(DiagramDragEventArgs e)
        {
            base.OnDropSelectedShapes(e);

            DTAnalyzer Analyzer = new DTAnalyzer(this.m_DTDataSheet.GetData(), this.m_DataFeed.Project);

            this.SaveSelection();
            this.RecordNewStateClassLocations(Analyzer);
            this.InternalRefreshLookups();
            this.InternalRefreshTransitionLines();

            //DEVTODO: It would be better not to do this, but there is no obvious way to tell
            //if the user is about to drop the shapes they are dragging.  Is there?

            this.m_DTDataSheet.BeginModifyRows();
            this.m_DTDataSheet.EndModifyRows();

            this.RestoreSelection();
            this.Focus();
        }
Пример #25
0
        public override void OnDragOver(DiagramDragEventArgs diagramDragEventArgs)
        {
            base.OnDragOver(diagramDragEventArgs);

            if (diagramDragEventArgs.Handled)
            {
                return;
            }

            if (diagramDragEventArgs.Data.GetData("Sawczyn.EFDesigner.EFModel.ModelEnum") is ModelEnum ||
                diagramDragEventArgs.Data.GetData("Sawczyn.EFDesigner.EFModel.ModelClass") is ModelClass ||
                IsAcceptableDropItem(diagramDragEventArgs))
            {
                diagramDragEventArgs.Effect = DragDropEffects.Copy;
            }
            else
            {
                diagramDragEventArgs.Effect = DragDropEffects.None;
            }
        }
Пример #26
0
        protected override void OnDropSelectedShapes(DiagramDragEventArgs e)
        {
            base.OnDropSelectedShapes(e);

            foreach (StockTypeShape Shape in this.SelectedShapes)
            {
                Debug.Assert(this.WorkspaceRectangle.Contains(Shape.Bounds));

                DataRow row = this.GetStockTypeRecord(Shape.StockTypeId);
                row[Constants.LOCATION_COLUMN_NAME] = RowColToLocation(Shape.Row, Shape.Column);
            }

            this.RefreshLocationLookups();
            this.RefreshFlowPathwayLines();

            //DEVTODO: It would be better not to do this, but there is no obvious way to tell
            //if the user is about to drop the shapes they are dragging.  Is there?

            this.m_FlowDiagramSheet.BeginModifyRows();
            this.m_FlowDiagramSheet.EndModifyRows();

            this.Focus();
        }
Пример #27
0
        /// <summary>
        /// Import d'un service
        /// </summary>
        /// <param name="e">The diagram drag event arguments.</param>
        public override void OnDragDrop(DiagramDragEventArgs e)
        {
            base.OnDragDrop(e);

            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                string txt = (string)e.Data.GetData(DataFormats.Text);
                using (
                    Transaction transaction = ModelElement.Store.TransactionManager.BeginTransaction("Import interface")
                    )
                {
                    IImportInterfaceHelper importer = ServiceLocator.Instance.GetService <IImportInterfaceHelper>();
                    if (importer == null)
                    {
                        return;
                    }
                    if (importer.ImportOperations(ModelElement as Layer, null, txt))
                    {
                        RebuildShape();
                        transaction.Commit();
                    }
                }
            }
        }
Пример #28
0
 /// <summary>
 /// Alerts listeners when the shape is dragged over its bounds.
 /// </summary>
 /// <param name="e">The diagram drag event arguments.</param>
 public override void OnDragOver(DiagramDragEventArgs e)
 {
     base.OnDragOver(e);
     DragDropHelper.OnDragOverLayer(this, e);
 }
 /// <summary>
 ///     The even handler when ojbects are dragged over the designer.
 /// </summary>
 /// <param name="e"></param>
 public override void OnDragEnter(DiagramDragEventArgs e)
 {
     // Depending on type of objects are being dragged, display the appropriate icons.
     _clipboardObjects = GetClipboardObjectFromDragEventArgs(e);
     if (_clipboardObjects != null)
     {
         e.Effect = GetDropEffects();
         e.Handled = true;
     }
     else
     {
         base.OnDragEnter(e);
     }
 }
Пример #30
0
 public override void OnDragDrop(DiagramDragEventArgs e)
 {
     base.OnDragDrop(e);
 }
 /// <summary>
 ///     Handler when EFObjects are dragged over designer.
 ///     Set the appropriate drag effect.
 /// </summary>
 /// <param name="e"></param>
 public override void OnDragOver(DiagramDragEventArgs e)
 {
     e.Effect = GetDropEffects();
     if (e.Effect != DragDropEffects.None)
     {
         e.Handled = true;
     }
     else
     {
         base.OnDragOver(e);
     }
 }
 /// <summary>
 ///     Retrieves the instance of EntitiesClipboardFormat from ClipboardData object.
 ///     return null if none exists.
 /// </summary>
 private static EntitiesClipboardFormat GetClipboardObjectFromDragEventArgs(DiagramDragEventArgs e)
 {
     if (e.Data.GetDataPresent(typeof(EntitiesClipboardFormat).Name, false))
     {
         return e.Data.GetData(typeof(EntitiesClipboardFormat).Name, false) as EntitiesClipboardFormat;
     }
     return null;
 }
        public override void OnDragOver(DiagramDragEventArgs e)
        {
            if (e.Data.GetFormats().Contains("VSToolboxUniqueID"))
            {
                var model = this.Diagram.ModelElement as nHydrateModel;
                var typeName = (e.Data.GetData("VSToolboxUniqueID") as MemoryStream).GetString().Replace("\0", string.Empty);
                if (typeName == "nHydrate2.DslPackage.ViewToolboxItem")
                {
                    if ((model.DiagramVisibility & VisibilityTypeConstants.View) != VisibilityTypeConstants.View)
                    {
                        e.Effect = DragDropEffects.None;
                        return;
                    }
                }
                else if (typeName == "nHydrate2.DslPackage.StoredProcedureToolboxItem")
                {
                    if ((model.DiagramVisibility & VisibilityTypeConstants.StoredProcedure) != VisibilityTypeConstants.StoredProcedure)
                    {
                        e.Effect = DragDropEffects.None;
                        return;
                    }
                }
                else if (typeName == "nHydrate2.DslPackage.FunctionToolboxItem")
                {
                    if ((model.DiagramVisibility & VisibilityTypeConstants.Function) != VisibilityTypeConstants.Function)
                    {
                        e.Effect = DragDropEffects.None;
                        return;
                    }
                }
            }

            base.OnDragOver(e);
        }
 /// <summary>
 ///     The event handler when objects are dropped to the designer.
 ///     If clipboard object is not null, we will go through the objects in the clipboard object and create appropriate Escher objects.
 /// </summary>
 /// <param name="e"></param>
 public override void OnDragDrop(DiagramDragEventArgs e)
 {
     try
     {
         Arranger.Start(e.IsDropLocationUserSpecified ? e.MousePosition : PointD.Empty);
         if (_clipboardObjects != null)
         {
             var modelDiagram = ModelElement.ModelXRef.GetExisting(this) as ModelDiagram;
             var cpc = new CommandProcessorContext(
                 ModelElement.EditingContext, EfiTransactionOriginator.EntityDesignerOriginatorId, EntityDesignerResources.Tx_DropItems);
             CommandProcessor.InvokeSingleCommand(
                 cpc, 
                 new CreateDiagramItemForEFElementsCommand(
                     GetEFElementNotInDiagramFromClipboardObject(_clipboardObjects),
                     modelDiagram, e.Shift || e.Control));
         }
         else
         {
             base.OnDragDrop(e);
         }
     }
     finally
     {
         _clipboardObjects = null;
         Arranger.End();
         if (e.IsDropLocationUserSpecified == false)
         {
             EnsureSelectionVisible();
         }
     }
 }
 public override void OnDragOver(DiagramDragEventArgs e)
 {
     base.OnDragOver(e);            
 }
Пример #36
0
        public override void OnDragDrop(DiagramDragEventArgs diagramDragEventArgs)
        {
            // came from model explorer?
            ModelElement element = (diagramDragEventArgs.Data.GetData("Sawczyn.EFDesigner.EFModel.ModelClass") as ModelElement)
                                   ?? (diagramDragEventArgs.Data.GetData("Sawczyn.EFDesigner.EFModel.ModelEnum") as ModelElement);

            if (element != null)
            {
                ShapeElement newShape = AddExistingModelElement(this, element);

                if (newShape != null)
                {
                    using (Transaction t = element.Store.TransactionManager.BeginTransaction("Moving pasted shapes"))
                    {
                        if (newShape is NodeShape nodeShape)
                        {
                            nodeShape.Location = diagramDragEventArgs.MousePosition;
                        }

                        t.Commit();
                    }
                }
            }
            else
            {
                if (IsDroppingExternal)
                {
                    DisableDiagramRules();
                    Cursor prev = Cursor.Current;
                    Cursor.Current = Cursors.WaitCursor;

                    List <ModelElement> newElements = null;
                    try
                    {
                        try
                        {
                            // add to the model
                            string[] filenames;

                            if (diagramDragEventArgs.Data.GetData("Text") is string concatenatedFilenames)
                            {
                                filenames = concatenatedFilenames.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                            }
                            else if (diagramDragEventArgs.Data.GetData("FileDrop") is string[] droppedFilenames)
                            {
                                filenames = droppedFilenames;
                            }
                            else
                            {
                                ErrorDisplay.Show(Store, "Unexpected error dropping files. Please create an issue in Github.");
                                return;
                            }

                            string[] existingFiles = filenames.Where(File.Exists).ToArray();
                            newElements = FileDropHelper.HandleMultiDrop(Store, existingFiles).ToList();

                            string[] missingFiles = filenames.Except(existingFiles).ToArray();

                            if (missingFiles.Any())
                            {
                                if (missingFiles.Length > 1)
                                {
                                    missingFiles[missingFiles.Length - 1] = "and " + missingFiles[missingFiles.Length - 1];
                                }

                                ErrorDisplay.Show(Store, $"Can't find files {string.Join(", ", missingFiles)}");
                            }
                        }
                        finally
                        {
                            // TODO: how to add shapes to the current diagram without taking forever? The trick is disabling line routing, but how?
                            #region Come back to this later

                            //if (newElements != null)
                            //{
                            // add to the active diagram
                            //int elementCount = newElements.Count;
                            //List<ShapeElement> newShapes = new List<ShapeElement>();

                            //using (Transaction t = Store.TransactionManager.BeginTransaction("adding diagram elements"))
                            //{
                            //   for (int index = 0; index < elementCount; index++)
                            //   {
                            //      ModelElement newElement = newElements[index];
                            //      StatusDisplay.Show($"Adding element {index + 1} of {elementCount}");

                            //      ForceAddShape = true;
                            //      FixUpAllDiagrams.FixUp(this, newElement);
                            //      newShapes.Add(newElement.GetFirstShapeElement());
                            //      ForceAddShape = false;
                            //   }

                            //   t.Commit();
                            //}

                            //using (Transaction t = Store.TransactionManager.BeginTransaction("adding diagram links"))
                            //{
                            //   for (int index = 0; index < elementCount; index++)
                            //   {
                            //      ModelElement newElement = newElements[index];
                            //      StatusDisplay.Show($"Linking {index + 1} of {elementCount}");

                            //      // find all element links that are attached to our element where the ends are in the diagram but the link isn't already in the diagram
                            //      List<ElementLink> elementLinks = Store.GetAll<ElementLink>()
                            //                                            .Where(link => link.LinkedElements.Contains(newElement)
                            //                                                        && link.LinkedElements.All(linkedElement => DisplayedElements.Contains(linkedElement))
                            //                                                        && !DisplayedElements.Contains(link))
                            //                                            .ToList();

                            //      foreach (ElementLink elementLink in elementLinks)
                            //      {
                            //         BinaryLinkShape linkShape = CreateChildShape(elementLink) as BinaryLinkShape;
                            //         newShapes.Add(linkShape);
                            //         NestedChildShapes.Add(linkShape);

                            //         switch (elementLink)
                            //         {
                            //            case Association a:
                            //               linkShape.FromShape = a.Source.GetFirstShapeElement() as NodeShape;
                            //               linkShape.ToShape = a.Target.GetFirstShapeElement() as NodeShape;
                            //               break;
                            //            case Generalization g:
                            //               linkShape.FromShape = g.Subclass.GetFirstShapeElement() as NodeShape;
                            //               linkShape.ToShape = g.Superclass.GetFirstShapeElement() as NodeShape;
                            //               break;
                            //         }
                            //      }
                            //   }

                            //   AutoLayoutShapeElements(newShapes);
                            //   t.Commit();
                            //}
                            //}
                            #endregion

                            IsDroppingExternal = false;
                        }
                    }
                    finally
                    {
                        EnableDiagramRules();
                        Cursor.Current = prev;

                        MessageDisplay.Show(newElements == null || !newElements.Any()
                                         ? "Import dropped files: no new elements added"
                                         : BuildMessage(newElements));

                        StatusDisplay.Show("");
                    }
                }
                else
                {
                    try
                    {
                        base.OnDragDrop(diagramDragEventArgs);
                    }
                    catch (ArgumentException)
                    {
                        // ignore. byproduct of multiple diagrams
                    }
                }
            }

            StatusDisplay.Show("");
            Invalidate();

            string BuildMessage(List <ModelElement> newElements)
            {
                int           classCount    = newElements.OfType <ModelClass>().Count();
                int           propertyCount = newElements.OfType <ModelClass>().SelectMany(c => c.Attributes).Count();
                int           enumCount     = newElements.OfType <ModelEnum>().Count();
                List <string> messageParts  = new List <string>();

                if (classCount > 0)
                {
                    messageParts.Add($"{classCount} classes");
                }

                if (propertyCount > 0)
                {
                    messageParts.Add($"{propertyCount} properties");
                }

                if (enumCount > 0)
                {
                    messageParts.Add($"{enumCount} enums");
                }

                return($"Import dropped files: added {(messageParts.Count > 1 ? string.Join(", ", messageParts.Take(messageParts.Count - 1)) + " and " + messageParts.Last() : messageParts.First())}");
            }
        }