手順 8 (オプション): リボンおよびアクションを定義する (Ribbon.xml)

作業ウィンドウ レイアウトを中間宣言型の Outlook ソリューションに追加したので、カスタム リボン ファイル定義を追加することもできます。リボン ファイルでは、リボンから呼び出されるアクションを指定します。

最終更新日: 2011年8月22日

適用対象: SharePoint Server 2010

たとえば多くのソリューションのリボンには、作業ウィンドウを開くボタンがあります。作業ウィンドウを起動する動作がアクションになります。リボン ファイルは、すべての Microsoft Office アプリケーションが使用する標準のリボン スキーマを使用します。

Business Connectivity Services のアクションには、URL ベースとコードベースの 2 種類のアクションがあります。URL ベースのアクションは、(リボン ボタンをクリックするなどして) アクションが実行されたときに、指定した URL に移動します。URL ベースのアクションは、Ribbon.xml ファイルで宣言的に定義できます。コード アクションは、リボン ボタンのクリック時にコードを実行し、開発者が作成しなければ使用できません。

コード サンプル: AdventureWorks2008 宣言型 Outlook ソリューション には、カスタム リボン メニュー [Contoso Sales Manager] があります。[Contoso Sales Manager] をクリックすると、次のように 2 つのリボン ボタンが表示されます。

  • Related Orders クリックされると、注文履歴のある作業ウィンドウを表示します。

  • Phone Lookup クリックされると、MSN の電話番号検索ページを参照するブラウザー ウィンドウが開き、顧客の電話番号を検索します。

リボン ファイルを作成するには

  1. BCS Artifact Generator ツール (英語)を使用して、BDC モデルに基づくフォーム領域マニフェスト ファイルを作成できます。

    または、以下のようにフォーム領域マニフェスト ファイルを手動で作成することもできます。

    1. SDK にある テンプレート: Ribbon.xml を見つけ、それをコピーして Solution Artifacts フォルダーに OutlookContactRibbon.xml という名前で保存します。

    2. XML エディターで OutlookContactRibbon.xml ファイルを開き編集します。Visual Studio で XML ファイルを開いている場合は、Office のリボン スキーマ (Office 2010 Reference: Office Fluent User Interface XML Schema (英語)) を追加します。これにより IntelliSense 機能を使用できるようになり、有効なエントリの作成に役立ちます。

    3. XML で EnterX というマークの付いた値を有効な値と置換します。次の XML の例は、編集後のファイルの内容を示しています。

      <customUI xmlns="https://schemas.microsoft.com/office/2006/01/customui" 
                onLoad="OnLoad" loadImage="GetImage">
        <ribbon>
          <tabs>
            <tab id="tabID" label="Contoso Sales Manager" 
                 getVisible="GetVisible" tag="Solution">
              <group id="CustomerSalesGroupID" label="Customer Sales" 
                     getVisible="GetVisible" 
                     tag="Context[OutlookContactCustomer.CustomerSalesGroupID]">
                <button id="relatedOrderHeaderButton"
                            size="large"
                            label="Customer Orders"
                            onAction="OnAction"
                            image="Arrow.jpg"
                          getEnabled ="GetEnabled"
                          tag="Action[OutlookContactCustomer.RelatedOrderHeaderAction]"
                        />
              </group>
              <group id="CustomerActionsGroupID" label="Customer Actions" 
                     getVisible="GetVisible" 
                     tag="Context[OutlookContactCustomer.CustomerActionsGroupID]">
                <button id="SearchCustomerByPhoneButton"
                           size="large"
                           label="Phone Lookup"
                           onAction="OnAction"
                           image="MagGlass.png"
                         getEnabled ="GetEnabled"
                         tag="Action[OutlookContactCustomer.SearchCustomerByPhoneAction]"
                        />
              </group>
            </tab>
          </tabs>
        </ribbon>
      </customUI>
      
    4. ファイルを保存して閉じます。

  2. OIR.config ファイルを開いて編集します。以下の例のように RibbonFileName 属性を追加し、読み込むリボン ファイルを指定するように OIR.config を更新します。

    <ContextDefinitionGroup 
      xsl:type="Declarative:DeclarativeContextDefinitionGroup" 
      ItemType="OutlookContact" RibbonFileName="OutlookContactRibbon.xml">
    
  3. 以下の例に示すように、注文の関連付け用の ContextDefinitionGroup を追加して、注文の外部アイテムを取得する方法を指定します。これは任意の手順です。リッチ リスト パーツにアクションを公開する場合に限り必要です。

    <ContextDefinitionGroup ItemType="EntityView">
      <!-- The content type has to be in the format: -->
      <!-- length_of_entity_namespace="" length_of_entity_name="" 
      length_of_view_name="" entity_namespace="" entity_name="" 
      view_name="" position_of_entity_namespace="" -->
      <ContextDefinition 
        ContentType="12 12 24 AWWSExample OrderHeader GetSalesOrderHeaderById 9" 
        xsl:type="Declarative:DeclarativeContextDefinition">
        <Entities>
          <Entity Name="OrderHeader" EntityTypeName="OrderHeader" 
                  EntityTypeNamespace="AWWSExample">
            <View Name="PrimaryEntityNameInContext" 
                  ViewName="GetSalesOrderHeaderById" 
                  Description="GetSalesOrderHeaderById" IsPrimary="true" />
          </Entity>
        </Entities>
        <Declarative:Layouts>
          <Declarative:Layout Name="Edit" LayoutFileName="EditOrderHeader">
            <Declarative:Properties>
              <Declarative:Property Name="AssociatedActionType" Value="Edit" />
            </Declarative:Properties>
          </Declarative:Layout>
        </Declarative:Layouts>
        <Declarative:Actions>
          <Declarative:CodeMethodAction MethodType="EditEntity" Name="Edit" 
                                        Caption="Edit Order" 
                                        DisplayLocations="ItemContextMenu" 
                                        DisplayOrder="2" Scope="ItemContext" />
        </Declarative:Actions>
      </ContextDefinition>
    </ContextDefinitionGroup>
    
  4. 必要なリボン ボタンに関する情報と、Customer ContextDefinition に関連するアクションを BCS Client Runtime に提供するように、OIR.config ファイルを更新します。以下のコードを Customer ContextDefinition の <Declarative:Layouts> タグの下に追加します。

    <Declarative:Actions>
      <Declarative:CodeMethodAction Name ="RelatedOrderHeaderAction" 
                                    MethodType ="ShowTaskpaneLayout">
        <Declarative:Parameters>
          <Declarative:ConstantParameter Name="Para1" 
                                         Value="RelatedOrderHeader" 
                                         ValueType="System.String"/>
        </Declarative:Parameters>
      </Declarative:CodeMethodAction>
      <Declarative:UrlAction 
        Name="SearchCustomerByPhoneAction" 
        Url="http://msn.whitepages.com/search/ReversePhone?full_phone={0}">
        <Declarative:Parameters>
          <Declarative:ExpressionParameter 
            Name="Para1" 
            EntityViewInstanceReference="PrimaryEntityNameInContext" 
            Expression="Phone"/>
        </Declarative:Parameters>
      </Declarative:UrlAction>
    </Declarative:Actions>
    <Declarative:ContextEventHandlers>
      <Declarative:ContextActivated ActionName="RelatedOrderHeaderAction" />
    </Declarative:ContextEventHandlers>
    
  5. ファイルを保存して閉じます。

  6. ソリューションをパッケージ化して展開し、予想どおりに動作するかどうかをテストします。

これで、中間宣言型の Outlook ソリューションが作成されました。