Changeset 70:46a6e0e6ccd4

Show
Ignore:
Timestamp:
05/21/08 19:36:46 (7 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Merge with d-fied sources of 3.4M7

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwtx/core/commands/AbstractHandler.d

    r3 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2004, 2006 IBM Corporation and others. 
     2 * Copyright (c) 2004, 2008 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    1414 
    1515import dwtx.core.commands.common.EventManager; 
    16 import dwtx.core.commands.IHandler
     16import dwtx.core.commands.IHandler2
    1717import dwtx.core.commands.IHandlerListener; 
    1818import dwtx.core.commands.HandlerEvent; 
     
    3333 * @since 3.1 
    3434 */ 
    35 public abstract class AbstractHandler : EventManager, IHandler { 
     35public abstract class AbstractHandler : EventManager, IHandler2 { 
     36 
     37    /** 
     38     * Track this base class enabled state. 
     39     *  
     40     * @since 3.4 
     41     */ 
     42    private bool baseEnabled = true; 
    3643 
    3744    /** 
     
    8289    /** 
    8390     * Whether this handler is capable of executing at this time. Subclasses may 
    84      * override this method. 
     91     * override this method. If clients override this method they should also 
     92     * consider overriding {@link #setEnabled(Object)} so they can be notified 
     93     * about framework execution contexts. 
    8594     * 
    8695     * @return <code>true</code> 
     96     * @see #setEnabled(Object) 
     97     * @see #setBaseEnabled(bool) 
    8798     */ 
    8899    public bool isEnabled() { 
    89         return true; 
     100        return baseEnabled; 
     101    } 
     102 
     103    /** 
     104     * Allow the default {@link #isEnabled()} to answer our enabled state. It 
     105     * will fire a HandlerEvent if necessary. If clients use this method they 
     106     * should also consider overriding {@link #setEnabled(Object)} so they can 
     107     * be notified about framework execution contexts. 
     108     *  
     109     * @param state 
     110     *            the enabled state 
     111     * @since 3.4 
     112     */ 
     113    protected void setBaseEnabled(bool state) { 
     114        if (baseEnabled is state) { 
     115            return; 
     116        } 
     117        baseEnabled = state; 
     118        fireHandlerChanged(new HandlerEvent(this, true, false)); 
     119    } 
     120 
     121    /** 
     122     * Called by the framework to allow the handler to update its enabled state 
     123     * by extracting the same information available at execution time. Clients 
     124     * may override if they need to extract information from the application 
     125     * context. 
     126     *  
     127     * @param evaluationContext 
     128     *            the application context. May be <code>null</code> 
     129     * @since 3.4 
     130     * @see #setBaseEnabled(bool) 
     131     */ 
     132    public void setEnabled(Object evaluationContext) { 
    90133    } 
    91134 
  • dwtx/core/commands/Command.d

    r43 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2004, 2007 IBM Corporation and others. 
     2 * Copyright (c) 2004, 2008 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    500500        // Perform the execution, if there is a handler. 
    501501        if ((handler !is null) && (handler.isHandled())) { 
     502            setEnabled(event.getApplicationContext()); 
    502503            if (!isEnabled()) { 
    503504                NotEnabledException exception = new NotEnabledException( 
     
    736737     * Returns the help context identifier associated with this command. This 
    737738     * method should not be called by clients. Clients should use 
    738      * {@link CommandManager#getHelpContextId(String)} instead. 
     739     * {@link CommandManager#getHelpContextId(Command)} instead. 
    739740     * 
    740741     * @return The help context identifier for this command; may be 
     
    862863 
    863864        return handler.isEnabled(); 
     865    } 
     866     
     867    /** 
     868     * Called be the framework to allow the handler to update its enabled state. 
     869     *  
     870     * @param evaluationContext 
     871     *            the state to evaluate against. May be <code>null</code> 
     872     *            which indicates that the handler can query whatever model that 
     873     *            is necessary.  This context must not be cached. 
     874     * @since 3.4 
     875     */ 
     876    public void setEnabled(Object evaluationContext) { 
     877        if (handler instanceof IHandler2) { 
     878            ((IHandler2) handler).setEnabled(evaluationContext); 
     879        } 
    864880    } 
    865881 
     
    10051021 
    10061022    /** 
    1007      * @return 
     1023     * @return the handler listener 
    10081024     */ 
    10091025    private IHandlerListener getHandlerListener() { 
  • dwtx/core/commands/CommandManager.d

    r40 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2004, 2006 IBM Corporation and others. 
     2 * Copyright (c) 2004, 2007 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    207207    /** 
    208208     * Unescapes special characters in the command id, parameter ids and 
    209      * parameter values for {@link #deserialize()}. The special characters 
     209     * parameter values for {@link #deserialize(String)}. The special characters 
    210210     * {@link #PARAMETER_START_CHAR}, {@link #PARAMETER_END_CHAR}, 
    211211     * {@link #ID_VALUE_CHAR}, {@link #PARAMETER_SEPARATOR_CHAR} and 
    212212     * {@link #ESCAPE_CHAR} are escaped by prepending an {@link #ESCAPE_CHAR} 
    213213     * character. 
     214     * <p> 
     215     * See also ParameterizedCommand.escape(String) 
     216     * </p> 
    214217     * 
    215218     * @param escapedText 
     
    221224     *             if <code>escapedText</code> contains an invalid escape 
    222225     *             sequence 
    223      * @see ParameterizedCommand#escape(String) 
    224226     * @since 3.2 
    225227     */ 
     
    297299     * manager. 
    298300     */ 
    299     private IExecutionListener executionListener = null; 
     301    private IExecutionListenerWithChecks executionListener = null; 
    300302 
    301303    /** 
     
    730732     *            <code>null</code>. 
    731733     * @return an array of parameterizations; may be <code>null</code>. 
    732      * @throws NotDefinedException 
    733      *             if the command is not defined 
    734734     * @throws SerializationException 
    735735     *             if there is an error deserializing the parameters 
     
    988988 
    989989    } 
     990    /** 
     991     * Fires the <code>notEnabled</code> event for 
     992     * <code>executionListeners</code>. 
     993     * <p> 
     994     * <b>Note:</b> This supports bridging actions to the command framework, 
     995     * and should not be used outside the framework. 
     996     * </p> 
     997     *  
     998     * @param commandId 
     999     *            The command id of the command about to execute, never 
     1000     *            <code>null</code>. 
     1001     * @param exception 
     1002     *            The exception, never <code>null</code>. 
     1003     * @since 3.4 
     1004     */ 
     1005    public void fireNotEnabled(String commandId, NotEnabledException exception) { 
     1006        if (executionListener !is null) { 
     1007            executionListener.notEnabled(commandId, exception); 
     1008        } 
     1009    } 
     1010     
     1011    /** 
     1012     * Fires the <code>notDefined</code> event for 
     1013     * <code>executionListeners</code>. 
     1014     * <p> 
     1015     * <b>Note:</b> This supports bridging actions to the command framework, 
     1016     * and should not be used outside the framework. 
     1017     * </p> 
     1018     *  
     1019     * @param commandId 
     1020     *            The command id of the command about to execute, never 
     1021     *            <code>null</code>. 
     1022     * @param exception 
     1023     *            The exception, never <code>null</code>. 
     1024     * @since 3.4 
     1025     */ 
     1026    public void fireNotDefined(String commandId, NotDefinedException exception) { 
     1027        if (executionListener !is null) { 
     1028            executionListener.notDefined(commandId, exception); 
     1029        } 
     1030    } 
     1031     
     1032    /** 
     1033     * Fires the <code>preExecute</code> event for 
     1034     * <code>executionListeners</code>. 
     1035     * <p> 
     1036     * <b>Note:</b> This supports bridging actions to the command framework, 
     1037     * and should not be used outside the framework. 
     1038     * </p> 
     1039     *  
     1040     * @param commandId 
     1041     *            The command id of the command about to execute, never 
     1042     *            <code>null</code>. 
     1043     * @param event 
     1044     *            The event that triggered the command, may be <code>null</code>. 
     1045     * @since 3.4 
     1046     */ 
     1047    public void firePreExecute(String commandId, ExecutionEvent event) { 
     1048        if (executionListener !is null) { 
     1049            executionListener.preExecute(commandId, event); 
     1050        } 
     1051    } 
     1052     
     1053    /** 
     1054     * Fires the <code>postExecuteSuccess</code> event for 
     1055     * <code>executionListeners</code>. 
     1056     * <p> 
     1057     * <b>Note:</b> This supports bridging actions to the command framework, 
     1058     * and should not be used outside the framework. 
     1059     * </p> 
     1060     *  
     1061     * @param commandId 
     1062     *            The command id of the command executed, never 
     1063     *            <code>null</code>. 
     1064     * @param returnValue 
     1065     *            The value returned from the command, may be <code>null</code>. 
     1066     * @since 3.4 
     1067     */ 
     1068    public void firePostExecuteSuccess(String commandId, Object returnValue) { 
     1069        if (executionListener !is null) { 
     1070            executionListener.postExecuteSuccess(commandId, returnValue); 
     1071        } 
     1072    } 
     1073     
     1074    /** 
     1075     * Fires the <code>postExecuteFailure</code> event for 
     1076     * <code>executionListeners</code>. 
     1077     * <p> 
     1078     * <b>Note:</b> This supports bridging actions to the command framework, 
     1079     * and should not be used outside the framework. 
     1080     * </p> 
     1081     *  
     1082     * @param commandId 
     1083     *            The command id of the command executed, never 
     1084     *            <code>null</code>. 
     1085     * @param exception 
     1086     *            The exception, never <code>null</code>. 
     1087     * @since 3.4 
     1088     */ 
     1089    public void firePostExecuteFailure(String commandId,  
     1090            ExecutionException exception) { 
     1091        if (executionListener !is null) { 
     1092            executionListener.postExecuteFailure(commandId, exception); 
     1093        } 
     1094    } 
    9901095} 
  • dwtx/core/commands/IHandler.d

    r3 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2004, 2005 IBM Corporation and others. 
     2 * Copyright (c) 2004, 2008 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    1515import dwtx.core.commands.IHandlerListener; 
    1616import dwtx.core.commands.ExecutionEvent; 
    17  
    1817 
    1918/** 
     
    6261    /** 
    6362     * Returns whether this handler is capable of executing at this moment in 
    64      * time. 
     63     * time. If the enabled state is other than true clients should also 
     64     * consider implementing IHandler2 so they can be notified about framework 
     65     * execution contexts. 
    6566     * 
    6667     * @return <code>true</code> if the command is enabled; <code>false</code> 
    6768     *         otherwise. 
     69     * @see IHandler2#setEnabled(Object) 
    6870     */ 
    6971    public bool isEnabled(); 
  • dwtx/core/commands/ParameterizedCommand.d

    r43 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2005, 2007 IBM Corporation and others. 
     2 * Copyright (c) 2005, 2008 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    88 * Contributors: 
    99 *     IBM Corporation - initial API and implementation 
     10 *     Benjamin Muskalla - bug 222861 [Commands] ParameterizedCommand#equals broken 
    1011 * Port to the D programming language: 
    1112 *     Frank Benoit <benoit@tionex.de> 
     
    122123     * @return a <code>String</code> representing <code>rawText</code> with 
    123124     *         special serialization characters escaped 
    124      * @see CommandManager#unescape(String) 
    125125     * @since 3.2 
    126126     */ 
     
    319319 
    320320    /** 
     321     * Take a command and a map of parameter IDs to values, and generate the 
     322     * appropriate parameterized command. 
     323     *  
     324     * @param command 
     325     *            The command object. Must not be <code>null</code>. 
     326     * @param parameters 
     327     *            A map of String parameter ids to objects. May be 
     328     *            <code>null</code>. 
     329     * @return the parameterized command, or <code>null</code> if it could not 
     330     *         be generated 
     331     * @since 3.4 
     332     */ 
     333    public static final ParameterizedCommand generateCommand(Command command, 
     334            Map parameters) { 
     335        // no parameters 
     336        if (parameters is null || parameters.isEmpty()) { 
     337            return new ParameterizedCommand(command, null); 
     338        } 
     339 
     340        try { 
     341            ArrayList parms = new ArrayList(); 
     342            Iterator i = parameters.keySet().iterator(); 
     343 
     344            // iterate over given parameters 
     345            while (i.hasNext()) { 
     346                String key = (String) i.next(); 
     347                IParameter parameter = null; 
     348                // get the parameter from the command 
     349                parameter = command.getParameter(key); 
     350 
     351                // if the parameter is defined add it to the parameter list 
     352                if (parameter is null) { 
     353                    return null; 
     354                } 
     355                ParameterType parameterType = command.getParameterType(key); 
     356                if (parameterType is null) { 
     357                    parms.add(new Parameterization(parameter, 
     358                            (String) parameters.get(key))); 
     359                } else { 
     360                    AbstractParameterValueConverter valueConverter = parameterType 
     361                            .getValueConverter(); 
     362                    if (valueConverter !is null) { 
     363                        String val = valueConverter.convertToString(parameters 
     364                                .get(key)); 
     365                        parms.add(new Parameterization(parameter, val)); 
     366                    } else { 
     367                        parms.add(new Parameterization(parameter, 
     368                                (String) parameters.get(key))); 
     369                    } 
     370                } 
     371            } 
     372 
     373            // convert the parameters to an Parameterization array and create 
     374            // the command 
     375            return new ParameterizedCommand(command, (Parameterization[]) parms 
     376                    .toArray(new Parameterization[parms.size()])); 
     377        } catch (NotDefinedException e) { 
     378        } catch (ParameterValueConversionException e) { 
     379        } 
     380        return null; 
     381    } 
     382 
     383    /** 
    321384     * The base command which is being parameterized. This value is never 
    322385     * <code>null</code>. 
     
    347410     * @param parameterizations 
    348411     *            An array of parameterizations binding parameters to values for 
    349      *            the command. This value may be <code>null</code>. This 
    350      *            argument is not copied; if you need to make changes to it 
    351      *            after constructing this parameterized command, then make a 
    352      *            copy yourself. 
     412     *            the command. This value may be <code>null</code>. 
    353413     */ 
    354414    public this(Command command, 
     
    360420 
    361421        this.command = command; 
    362         this.parameterizations = (parameterizations is null || parameterizations.length is 0) ? null 
    363                 : parameterizations; 
     422        IParameter[] parms = null; 
     423        try { 
     424            parms = command.getParameters(); 
     425        } catch (NotDefinedException e) { 
     426            // This should not happen. 
     427        } 
     428        if (parameterizations !is null && parameterizations.length>0 && parms !is null) { 
     429            int parmIndex = 0; 
     430            Parameterization[] params = new Parameterization[parameterizations.length]; 
     431            for (int j = 0; j < parms.length; j++) { 
     432                for (int i = 0; i < parameterizations.length; i++) { 
     433                    Parameterization pm = parameterizations[i]; 
     434                    if (parms[j].equals(pm.getParameter())) { 
     435                        params[parmIndex++] = pm; 
     436                    } 
     437                } 
     438            } 
     439            this.parameterizations = params; 
     440        } else { 
     441            this.parameterizations = null; 
     442        } 
    364443    } 
    365444 
     
    549628    } 
    550629 
    551     /* (non-Javadoc) 
     630    /* 
     631     * (non-Javadoc) 
     632     *  
    552633     * @see java.lang.Object#hashCode() 
    553634     */ 
  • dwtx/core/commands/common/CommandException.d

    r43 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2004, 2005 IBM Corporation and others. 
     2 * Copyright (c) 2004, 2007 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    2222 * 
    2323 * @since 3.1 
     24 * @noextend This class is not intended to be subclassed by clients. 
    2425 */ 
    2526public abstract class CommandException : Exception { 
    2627 
     28    /** 
     29     * Generated serial version UID for this class. 
     30     *  
     31     * @since 3.4 
     32     */ 
     33    private static final long serialVersionUID = 5389763628699257234L; 
     34     
    2735    /** 
    2836     * This member variable is required here to allow us to compile against JCL 
  • dwtx/core/commands/common/IIdentifiable.d

    r3 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2006 IBM Corporation and others. 
     2 * Copyright (c) 2006, 2007 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    1010 * Port to the D programming language: 
    1111 *     Frank Benoit <benoit@tionex.de> 
    12  ******************************************************************************/ 
    13  
     12 *******************************************************************************/ 
    1413module dwtx.core.commands.common.IIdentifiable; 
    1514import dwt.dwthelper.utils; 
     
    3029     * @return The identifier; never <code>null</code>. 
    3130     */ 
    32    String getId(); 
     31    String getId(); 
    3332} 
  • dwtx/core/commands/common/NamedHandleObjectComparator.d

    r3 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2005 IBM Corporation and others. 
     2 * Copyright (c) 2005, 2007 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    1010 * Port to the D programming language: 
    1111 *     Frank Benoit <benoit@tionex.de> 
    12  ******************************************************************************/ 
    13  
     12 *******************************************************************************/ 
    1413module dwtx.core.commands.common.NamedHandleObjectComparator; 
    1514 
    16 // import java.util.Comparator; 
    1715import dwtx.core.commands.common.NotDefinedException; 
    1816import dwtx.core.commands.common.NamedHandleObject; 
    1917import dwtx.core.internal.commands.util.Util; 
    2018import dwt.dwthelper.utils; 
    21  
    2219/** 
    2320 * Comparator for instances of <code>NamedHandleObject</code> for display to 
  • dwtx/core/commands/operations/AbstractOperation.d

    r43 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2005, 2006 IBM Corporation and others. 
     2 * Copyright (c) 2005, 2008 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    5252     * 
    5353     * @param label 
    54      *            the label to be used for the operation. 
     54     *            the label to be used for the operation. Should never be 
     55     *            <code>null</code>. 
    5556     */ 
    5657    public this(String label) { 
     58        Assert.isNotNull(label); 
    5759        this.label = label; 
    5860        contexts = new ArraySeq!(IUndoContext); 
     
    144146     * 
    145147     * @param name 
    146      *            the string to be used for the label. 
     148     *            the string to be used for the label. Should never be 
     149     *            <code>null</code>. 
    147150     */ 
    148151    public void setLabel(String name) { 
  • dwtx/core/commands/operations/IUndoableOperation.d

    r3 r70  
    11/******************************************************************************* 
    2  * Copyright (c) 2005 IBM Corporation and others. 
     2 * Copyright (c) 2005, 2008 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
    44 * are made available under the terms of the Eclipse Public License v1.0 
     
    159159