use of org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement 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.adt.design.editparts.model.IGraphElement in project webtools.sourceediting by eclipse.
the class TopLevelComponentEditPart method performRequest.
public void performRequest(Request request) {
// Do not open on or set focus on direct edit type
if (request.getType() == RequestConstants.REQ_OPEN) {
Object model = getModel();
if (model instanceof IGraphElement) {
if (((IGraphElement) model).isFocusAllowed()) {
if (request instanceof LocationRequest) {
LocationRequest locationRequest = (LocationRequest) request;
Point p = locationRequest.getLocation();
if (hitTest(labelHolder, p)) {
performDrillDownAction();
}
}
}
} else if (model instanceof XSDSchemaDirectiveAdapter) {
if (request instanceof LocationRequest) {
LocationRequest locationRequest = (LocationRequest) request;
Point p = locationRequest.getLocation();
if (hitTest(labelHolder, p)) {
XSDSchemaDirective dir = (XSDSchemaDirective) ((XSDSchemaDirectiveAdapter) model).getTarget();
String schemaLocation = "";
// force load of imported schema
if (dir instanceof XSDImportImpl) {
((XSDImportImpl) dir).importSchema();
}
if (dir.getResolvedSchema() != null) {
schemaLocation = URIHelper.removePlatformResourceProtocol(dir.getResolvedSchema().getSchemaLocation());
if (schemaLocation != null) {
OpenOnSelectionHelper.openXSDEditor(dir.getResolvedSchema());
}
}
}
}
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement in project webtools.sourceediting by eclipse.
the class DesignViewGraphicalViewer method selectionChanged.
// this method is called when something changes in the selection manager
// (e.g. a selection occured from another view)
public void selectionChanged(SelectionChangedEvent event) {
Object selectedObject = null;
ISelection eventSelection = event.getSelection();
if (eventSelection instanceof StructuredSelection) {
selectedObject = ((StructuredSelection) eventSelection).getFirstElement();
}
// if (event.getSource() instanceof ADTContentOutlinePage)
if (selectedObject != null) {
if (event.getSource() != internalSelectionProvider) {
if (selectedObject instanceof IStructure) {
if (((getInput() instanceof IModel) && (event.getSource() instanceof ADTContentOutlinePage)) || (!(getInput() instanceof IModel))) {
if ((selectedObject instanceof IGraphElement) && ((IGraphElement) selectedObject).isFocusAllowed()) {
if (!(event.getSource() instanceof org.eclipse.jface.viewers.IPostSelectionProvider)) {
setInputAndMarkLocation((IStructure) selectedObject);
}
}
}
} else if (selectedObject instanceof IGraphElement) {
if (((IGraphElement) selectedObject).isFocusAllowed() && ((event.getSource() instanceof ADTContentOutlinePage))) {
setInputAndMarkLocation((IADTObject) selectedObject);
} else if (!((IGraphElement) selectedObject).isFocusAllowed()) {
// We encountered an object that is not a valid input to the graph viewer
// Now find the top container that can be a valid input
IADTObject obj = ((IGraphElement) selectedObject).getTopContainer();
if (event.getSource() instanceof ADTContentOutlinePage) {
// change the inputs
if (// Don't change inputs if the obj is already the input
obj != null && getInput() != obj)
setInputAndMarkLocation(obj);
} else if (event.getSource() instanceof CommonSelectionManager) {
// otherwise, inputs will change unexpectedly!!
if (getInput() instanceof IModel) {
if (obj != null)
setInput(obj);
}
} else if (event.getSource() instanceof org.eclipse.jface.viewers.IPostSelectionProvider) {
// of anonymous types
if (obj != null)
setInput(obj);
} else {
if (obj != null && getInput() instanceof IModel)
setInputAndMarkLocation(obj);
}
}
if (selectedObject instanceof IField) {
IField field = (IField) selectedObject;
if ((!field.isGlobal() && getInput() instanceof IModel) || (!field.isGlobal() && !(event.getSource() instanceof CommonSelectionManager))) {
IADTObject obj = ((IGraphElement) selectedObject).getTopContainer();
if (obj != null)
setInputAndMarkLocation(obj);
} else if (field.isGlobal() && !(getInput() instanceof IModel)) {
if (event.getSource() instanceof org.eclipse.jface.viewers.IPostSelectionProvider)
setInput(field);
else
setInputAndMarkLocation(field);
}
}
} else if (selectedObject instanceof IField) {
IField field = (IField) selectedObject;
if ((field.isGlobal() && (getInput() instanceof IModel) && (event.getSource() instanceof ADTContentOutlinePage)) || ((field.isGlobal() && !(getInput() instanceof IModel)))) {
setInputAndMarkLocation(field);
}
} else if (selectedObject instanceof IModelProxy) {
IModelProxy adapter = (IModelProxy) selectedObject;
if (selectedObject instanceof RedefineCategoryAdapter) {
RedefineCategoryAdapter selectionAdapter = (RedefineCategoryAdapter) selectedObject;
XSDRedefineAdapter selectionParentAdapter = selectionAdapter.getXsdRedefineAdapter();
setInputAndMarkLocation(selectionParentAdapter);
} else if (getInput() != adapter.getModel())
setInput(adapter.getModel());
} else if (selectedObject instanceof IModel) {
if (getInput() != selectedObject)
setInput((IModel) selectedObject);
}
EditPart editPart = getEditPart(getRootEditPart(), selectedObject);
if (editPart != null) {
setSelection(new StructuredSelection(editPart));
setFocus(editPart);
}
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement in project webtools.sourceediting by eclipse.
the class RootContentEditPart method getModelChildren.
protected List getModelChildren() {
collections = new ArrayList();
if (getModel() != null) {
Object obj = getModel();
IADTObject focusObject = null;
if (obj instanceof IStructure) {
if (obj instanceof IGraphElement) {
if (((IGraphElement) obj).isFocusAllowed())
focusObject = (IStructure) obj;
}
} else if (obj instanceof IField) {
focusObject = (IField) obj;
} else if (obj instanceof IModel) {
focusObject = (IModel) obj;
collections.add(focusObject);
return collections;
} else if (obj instanceof IType) {
if (obj instanceof IGraphElement) {
if (((IGraphElement) obj).isFocusAllowed()) {
focusObject = (IType) obj;
}
}
} else if (obj instanceof IGraphElement) {
if (((IGraphElement) obj).isFocusAllowed()) {
focusObject = (IADTObject) obj;
collections.add(focusObject);
return collections;
}
}
if (focusObject != null) {
RootHolder holder = new RootHolder(focusObject);
collections.add(holder);
return collections;
}
}
return collections;
}
Aggregations