/// <summary>
 /// Sets the selection.
 /// </summary>
 /// <param name="selectProv">The selection provider - commonly this is the document.</param>
 /// <param name="selection">The selection. Use <c>null</c> to reset the selection.</param>
 internal static bool SetSelection(XSelectionSupplier selectProv, Object selection = null)
 {
     if (selectProv != null)
     {
         return(selectProv.select(Any.Get(selection)));
     }
     return(false);
 }
 /// <summary>
 /// Gets the selection.
 /// </summary>
 /// <param name="selectProv">The selection provider - commonly this is the document.</param>
 /// <returns>the selection or <c>null</c></returns>
 internal static Object GetSelection(XSelectionSupplier selectProv)
 {
     if (selectProv != null)
     {
         var selection = selectProv.getSelection().Value;
         return(selection);
     }
     return(null);
 }
 private void fireSelectionChangedEvent(XSelectionSupplier selectionSupplier, Object sender)
 {
     if (SelectionChanged != null && selectionSupplier != null)
     {
         Object selection = new Object();
         selection = GetSelection(selectionSupplier);
         try
         {
             SelectionChanged.DynamicInvoke(sender, new OoSelectionChandedEventArgs(selection));
         }
         catch { }
     }
 }
        /// <summary>
        /// Executes a dispatch on a previously (GUI) selected object.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="docSelSuppl">The document sel suppl.</param>
        /// <param name="commandUrl">The command URL.</param>
        /// <param name="docViewContrl">The document view contrl.</param>
        /// <param name="_frame">The frame.</param>
        /// <param name="_sFlag">The s flag.</param>
        /// <param name="args">The arguments.</param>
        /// <exception cref="System.ArgumentException">Objects could not be selected. - obj</exception>
        internal static bool CallDispatchOnObject(
            Object obj, XSelectionSupplier docSelSuppl,
            string commandUrl, XDispatchProvider docViewContrl,
            String _frame = "", int _sFlag = 0, PropertyValue[] args = null)
        {
            if (obj != null && docSelSuppl != null &&
                docViewContrl != null && !String.IsNullOrWhiteSpace(commandUrl))
            {
                // you have to select objects to call commands
                try
                {
                    docSelSuppl.select(Any.Get(obj));
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Objects could not be selected.", "obj", ex);
                }

                return(CallDispatch(commandUrl, docViewContrl, _frame, _sFlag, args));
            }
            return(false);
        }
        /// <summary>
        /// Registers the listener to the given object.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public bool RegisterListenerToElement(Object element)
        {
            XSelectionSupplier supl = element as XSelectionSupplier;

            //TODO: maybe extend this
            if (supl == null && element is XModel)
            {
                XModel model      = element as XModel;
                var    controller = model.getCurrentController();
                if (controller != null && controller is XSelectionSupplier)
                {
                    supl = controller as XSelectionSupplier;
                }
            }

            if (supl != null)
            {
                try { supl.removeSelectionChangeListener(Instance.eventForwarder); }
                catch { }
                try
                {
                    supl.addSelectionChangeListener(Instance.eventForwarder);
                    return(true);
                }
                catch
                {
                    System.Threading.Thread.Sleep(5);
                    try
                    {
                        supl.addSelectionChangeListener(Instance.eventForwarder);
                        return(true);
                    }
                    catch { }
                }
            }

            return(false);
        }
        //static readonly Object _selectionLock = new Object();
        /// <summary>
        /// Get the current selection.
        /// </summary>
        /// <param name="selectionSupplier">The selection supplier.</param>
        /// <returns><c>false</c> if no selection could be achieved; otherwise and [XShapes] collection</returns>
        /// <remarks>This request is locked and time limited to 100 ms.</remarks>
        public static Object GetSelection(XSelectionSupplier selectionSupplier)
        {
            Object selection = false;

            if (selectionSupplier != null)
            {
                //FIXME: you cannot do this in a time limited execution this will lead to an hang on -- why??????
                try
                {
                    lock (selectionSupplier)
                    {
                        TimeLimitExecutor.WaitForExecuteWithTimeLimit(100, () =>
                        {
                            Thread.BeginCriticalRegion();
                            var anySelection = selectionSupplier.getSelection();
                            Thread.EndCriticalRegion();

                            if (anySelection.hasValue())
                            {
                                selection = anySelection.Value;
                            }
                            else
                            {
                                selection = null;
                            }
                        }, "GetSelection");
                    }
                }
                catch (DisposedException)
                {
                    Logger.Instance.Log(LogPriority.DEBUG, "OoSelectionObserver", "Selection supplier disposed");
                    OO.CheckConnection();
                }
                catch (ThreadAbortException) { }
                catch (ThreadInterruptedException) { }
            }
            return(selection);
        }
예제 #7
0
        private static void Copy(XController controller, Object selection, XTransferableSupplier xTransferableSupplier)
        {
            if (xTransferableSupplier != null)
            {
                // get selection supplier
                XSelectionSupplier xSelectionSupplier = controller as XSelectionSupplier;

                if (xSelectionSupplier != null)
                {
                    // select the objects to select
                    try
                    {
                        xSelectionSupplier.select(Any.Get(selection));
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException("Object can't be set as selection", "selection", ex);
                    }

                    XTransferable transfarable = xTransferableSupplier.getTransferable();
                }
            }
        }
 /// <summary>
 /// Calls an actions with a previously selection change and a selection reset afterwards.
 /// </summary>
 /// <param name="act">The action to call.</param>
 /// <param name="selectProv">The selection provider - commonly this is the document.</param>
 /// <param name="selection">The selection. Use <c>null</c> to reset the selection.</param>
 internal static void ActionWithChangeAndResetSelection(Action act, XSelectionSupplier selectProv, Object selection = null)
 {
     try
     {
         TimeLimitExecutor.ExecuteWithTimeLimit(1000, () =>
         {
             try
             {
                 var oldSel = GetSelection(selectProv);
                 Thread.Sleep(80);
                 var succ = SetSelection(selectProv, selection);
                 Thread.Sleep(80);
                 if (succ && act != null)
                 {
                     act.Invoke();
                     if (Thread.CurrentThread.IsAlive)
                     {
                         Thread.Sleep(250);
                     }
                 }
                 Thread.Sleep(100);
                 SetSelection(selectProv, oldSel);
             }
             catch (Exception ex) {
                 Logger.Instance.Log(LogPriority.ALWAYS, "OoDispatchHelper", "[FATAL ERROR] Can't call dispatch command with selection - Thread interrupted:", ex);
             }
         }, "Delete Object");
     }
     catch (ThreadInterruptedException ex)
     {
         Logger.Instance.Log(LogPriority.ALWAYS, "OoDispatchHelper", "[FATAL ERROR] Can't call dispatch command with selection - Thread interrupted:", ex);
     }
     catch (Exception ex)
     {
         Logger.Instance.Log(LogPriority.ALWAYS, "OoDispatchHelper", "[FATAL ERROR] Can't call dispatch command with selection:", ex);
     }
 }
 /// <summary>
 /// Calls an actions with a previously selection change and a selection reset afterwards.
 /// </summary>
 /// <param name="act">The action to call.</param>
 /// <param name="selectProv">The selection provider - commonly this is the document.</param>
 /// <param name="selection">The selection. Use <c>null</c> to reset the selection.</param>
 internal static void ActionWithChangeAndResetSelection(Action act, XSelectionSupplier selectProv, Object selection = null)
 {
     var oldSel = GetSelection(selectProv);
     SetSelection(selectProv, selection);
     if (act != null) { act.Invoke(); }
     SetSelection(selectProv, oldSel);
 }
 /// <summary>
 /// Sets the selection.
 /// </summary>
 /// <param name="selectProv">The selection provider - commonly this is the document.</param>
 /// <param name="selection">The selection. Use <c>null</c> to reset the selection.</param>
 internal static void SetSelection(XSelectionSupplier selectProv, Object selection = null)
 {
     if (selectProv != null)
     {
         selectProv.select(Any.Get(selection));
     }
 }
 /// <summary>
 /// Gets the selection.
 /// </summary>
 /// <param name="selectProv">The selection provider - commonly this is the document.</param>
 /// <returns>the selection or <c>null</c></returns>
 internal static Object GetSelection(XSelectionSupplier selectProv)
 {
     if (selectProv != null)
     {
         var selection = selectProv.getSelection().Value;
         return selection;
     }
     return null;
 }
        /// <summary>
        /// Executes a dispatch on a previously (GUI) selected object.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="docSelSuppl">The document sel suppl.</param>
        /// <param name="commandUrl">The command URL.</param>
        /// <param name="docViewContrl">The document view contrl.</param>
        /// <param name="_frame">The frame.</param>
        /// <param name="_sFlag">The s flag.</param>
        /// <param name="args">The arguments.</param>
        /// <exception cref="System.ArgumentException">Objects could not be selected. - obj</exception>
        internal static bool CallDispatchOnObject(
            Object obj, XSelectionSupplier docSelSuppl,
            string commandUrl, XDispatchProvider docViewContrl,
            String _frame = "", int _sFlag = 0, PropertyValue[] args = null)
        {

            if (obj != null && docSelSuppl != null
                && docViewContrl != null && !String.IsNullOrWhiteSpace(commandUrl))
            {
                // you have to select objects to call commands
                try
                {
                    docSelSuppl.select(Any.Get(obj));
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Objects could not be selected.", "obj", ex);
                }

                return CallDispatch(commandUrl, docViewContrl, _frame, _sFlag, args);
            }
            return false;
        }
 private void fireSelectionChangedEvent(XSelectionSupplier selectionSupplier, Object sender)
 {
     if (SelectionChanged != null && selectionSupplier != null)
     {
         Object selection = new Object();
         selection = GetSelection(selectionSupplier);
         try
         {
             SelectionChanged.DynamicInvoke(sender, new OoSelectionChandedEventArgs(selection));
         }
         catch { }
     }
 }
 public static Object GetSelection(XSelectionSupplier selectionSupplier)
 {
     Object selection = null;
     if (selectionSupplier != null)
     {
         lock (_selectionLock)
         {
             //FIXME: you cannot do this in a time limited execution this will lead to an hang on -- why??????
             try
             {
                // TimeLimitExecutor.WaitForExecuteWithTimeLimit(20000, () =>
                 //{
                     Thread.BeginCriticalRegion();
                     var anySelection = selectionSupplier.getSelection();
                     Thread.EndCriticalRegion();
                 
                     if (anySelection.hasValue())
                     {
                         selection = anySelection.Value;
                     }
                 // }, "GetSelection");
             }
             catch (DisposedException)
             {
                 Logger.Instance.Log(LogPriority.DEBUG, "OoSelectionObserver", "Selection supplier disposed");
                 OO.CheckConnection();
             }
             catch (ThreadAbortException) { }
         }
     }
     return selection;
 }