Skip to main content
summaryrefslogtreecommitdiffstats
blob: 472d9605c0cedb530e6dbca7b3952f50df8fbbf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
 * Copyright (c) 2001, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.common.actions;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.contentoutline.ContentOutline;
import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
import org.eclipse.wst.xsd.ui.internal.adt.actions.BaseSelectionAction;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseFieldEditPart;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.IAutoDirectEdit;
import org.eclipse.wst.xsd.ui.internal.design.editparts.TopLevelComponentEditPart;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDSchema;

public class XSDBaseAction extends BaseSelectionAction
{
  XSDConcreteComponent addedComponent;

  public XSDBaseAction(IWorkbenchPart part)
  {
    super(part);
  }

  protected boolean calculateEnabled()
  {
    if (getWorkbenchPart() instanceof IEditorPart)
    {
      IEditorPart owningEditor = (IEditorPart)getWorkbenchPart();
      
      Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
      if (selection instanceof XSDBaseAdapter)
      {
        selection = ((XSDBaseAdapter) selection).getTarget();
      }
      XSDSchema xsdSchema = null;
      if (selection instanceof XSDConcreteComponent)
      {
        xsdSchema = ((XSDConcreteComponent)selection).getSchema();
      }
      
      if (xsdSchema != null && xsdSchema == owningEditor.getAdapter(XSDSchema.class))
      {
        return true;
      }
    }
    return false;
  }
  
  protected void doEdit(Object obj, IWorkbenchPart part)
  {
    if (obj instanceof TopLevelComponentEditPart)
    {
      TopLevelComponentEditPart editPart = (TopLevelComponentEditPart)obj;
      if (addedComponent == ((XSDBaseAdapter)editPart.getModel()).getTarget())
      {
        editPart.setScroll(true);
        editPart.addFeedback();
        editPart.doEditName(!(part instanceof ContentOutline));
      }
    }
    else if (obj instanceof BaseFieldEditPart)
    {
      BaseFieldEditPart editPart = (BaseFieldEditPart)obj;
      editPart.doEditName(!(part instanceof ContentOutline));
    }
    else if (obj instanceof IAutoDirectEdit)
    {
      ((IAutoDirectEdit)obj).doEditName(!(part instanceof ContentOutline));
    }
  }
}

Back to the top