use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class DeleteAction method run.
public void run() {
for (Iterator i = ((IStructuredSelection) getSelection()).iterator(); i.hasNext(); ) {
Object selection = i.next();
Command command = null;
boolean doSetInput = false;
boolean doSetModelAsInput = false;
IADTObject topLevelContainer = null;
IModel model = null;
if (selection instanceof IGraphElement) {
IGraphElement xsdObj = (IGraphElement) selection;
if (xsdObj instanceof XSDBaseAdapter) {
XSDBaseAdapter baseAdapter = (XSDBaseAdapter) xsdObj;
// is null and the read only check cannot be completed
if (baseAdapter == null || baseAdapter.isReadOnly()) {
continue;
}
topLevelContainer = xsdObj.getTopContainer();
if (topLevelContainer == selection) {
doSetInput = true;
doSetModelAsInput = true;
}
command = xsdObj.getDeleteCommand();
model = xsdObj.getModel();
}
}
if (command != null) {
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null) {
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow != null && workbenchWindow.getActivePage() != null) {
IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
if (editorPart != null) {
Object viewer = editorPart.getAdapter(GraphicalViewer.class);
if (viewer instanceof DesignViewGraphicalViewer) {
Object input = ((DesignViewGraphicalViewer) viewer).getInput();
if (input != selection) {
// Bug 86218 : Don't switch to top level view if the object we're deleting
// is not the input to the viewer
doSetInput = false;
}
}
}
}
}
command.execute();
if (doSetInput) {
if (model != null && doSetModelAsInput)
provider.setSelection(new StructuredSelection(model));
else if (topLevelContainer != null && !doSetModelAsInput)
provider.setSelection(new StructuredSelection(topLevelContainer));
}
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class BaseDirectEditAction method getSelection.
/* (non-Javadoc)
* @see org.eclipse.gef.ui.actions.SelectionAction#getSelection()
*/
protected ISelection getSelection() {
// always get selection from selection provider first
if (provider != null) {
Object selection = provider.getSelection();
if (selection instanceof StructuredSelection) {
Object object = ((StructuredSelection) selection).getFirstElement();
if (object instanceof XSDBaseAdapter) {
// We need to return an EditPart as the selection.
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
Object graphicalViewer = editor.getAdapter(GraphicalViewer.class);
if (graphicalViewer instanceof AbstractEditPartViewer) {
AbstractEditPartViewer viewer = (AbstractEditPartViewer) graphicalViewer;
EditPart editPart = (EditPart) viewer.getEditPartRegistry().get(object);
return new StructuredSelection(editPart);
}
}
}
}
return super.getSelection();
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class ModelGroupEditPart method getModelChildren.
protected List getModelChildren() {
// XSDModelGroupAdapter modelGroupAdapter = (XSDModelGroupAdapter)getModel();
// ArrayList ch = new ArrayList();
// ITreeElement [] tree = modelGroupAdapter.getChildren();
// int length = tree.length;
// for (int i = 0; i < length; i++)
// {
// ch.add(tree[i]);
// }
List list = new ArrayList();
XSDModelGroup xsdModelGroup = getXSDModelGroup();
for (Iterator i = xsdModelGroup.getContents().iterator(); i.hasNext(); ) {
XSDParticle next = (XSDParticle) i.next();
if (next.getContent() instanceof XSDElementDeclaration) {
XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) next.getContent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(elementDeclaration);
list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
}
if (next.getContent() instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition def = (XSDModelGroupDefinition) next.getContent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(def);
list.add(adapter);
} else if (next.getTerm() instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) next.getTerm();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(modelGroup);
list.add(adapter);
} else if (next.getTerm() instanceof XSDWildcard) {
XSDWildcard wildCard = (XSDWildcard) next.getTerm();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(wildCard);
list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
}
}
if (list.size() == 0)
list.add(new TargetConnectionSpaceFiller(null));
return list;
// return ch;
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class TopLevelComponentEditPart method doEditName.
public void doEditName(boolean addFromDesign) {
if (!addFromDesign)
return;
// removeFeedback();
Object object = ((XSDBaseAdapter) getModel()).getTarget();
if (object instanceof XSDNamedComponent) {
Point p = label.getLocation();
TopLevelNameDirectEditManager manager = new TopLevelNameDirectEditManager(TopLevelComponentEditPart.this, new TopLevelComponentLabelCellEditorLocator(TopLevelComponentEditPart.this, p), (XSDNamedComponent) object);
NameUpdateCommandWrapper wrapper = new NameUpdateCommandWrapper();
adtDirectEditPolicy.setUpdateCommand(wrapper);
manager.show();
}
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class XSDBaseFieldEditPart method refreshIcon.
protected void refreshIcon() {
IFieldFigure figure = getFieldFigure();
// our model implements ITreeElement
if (getModel() instanceof XSDBaseAdapter) {
Image image = ((XSDBaseAdapter) getModel()).getImage();
boolean isReadOnly = ((XSDBaseAdapter) getModel()).isReadOnly();
figure.getNameLabel().setIcon(image);
if (image != null) {
XSDConcreteComponent comp = (XSDConcreteComponent) ((XSDBaseAdapter) getModel()).getTarget();
figure.getNameLabel().setIcon(XSDCommonUIUtils.getUpdatedImage(comp, image, isReadOnly));
}
}
}
Aggregations