/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. */ package org.sintef.thingml.resource.thingml.ui.debug; @SuppressWarnings("restriction") public class ThingmlAdapterFactory implements org.eclipse.core.runtime.IAdapterFactory { @SuppressWarnings("rawtypes") public Object getAdapter(Object adaptableObject, Class adapterType) { if (adaptableObject instanceof org.eclipse.ui.texteditor.ITextEditor) { org.eclipse.ui.texteditor.ITextEditor editorPart = (org.eclipse.ui.texteditor.ITextEditor) adaptableObject; org.eclipse.core.resources.IResource resource = (org.eclipse.core.resources.IResource) editorPart.getEditorInput().getAdapter(org.eclipse.core.resources.IResource.class); if (resource != null) { String extension = resource.getFileExtension(); if (extension != null && extension.equals(new org.sintef.thingml.resource.thingml.mopp.ThingmlMetaInformation().getSyntaxName())) { return new org.sintef.thingml.resource.thingml.ui.debug.ThingmlLineBreakpointAdapter(); } } } if (adapterType == org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider.class && adaptableObject instanceof org.sintef.thingml.resource.thingml.debug.ThingmlDebugVariable) { final org.sintef.thingml.resource.thingml.debug.ThingmlDebugVariable variable = (org.sintef.thingml.resource.thingml.debug.ThingmlDebugVariable) adaptableObject; return new org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider() { public void update(org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate[] updates) { for (org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate update : updates) { try { update.setLabel(variable.getName(), 0); update.setLabel(variable.getValue().getValueString(), 1); update.done(); } catch (org.eclipse.debug.core.DebugException e) { } } } }; } if (adapterType == org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider.class && adaptableObject instanceof org.sintef.thingml.resource.thingml.debug.ThingmlDebugVariable) { final org.sintef.thingml.resource.thingml.debug.ThingmlDebugVariable variable = (org.sintef.thingml.resource.thingml.debug.ThingmlDebugVariable) adaptableObject; return new org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider() { public void update(org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate[] updates) { try { for (org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate update : updates) { org.eclipse.debug.core.model.IValue value = variable.getValue(); org.sintef.thingml.resource.thingml.debug.ThingmlDebugValue castedValue = (org.sintef.thingml.resource.thingml.debug.ThingmlDebugValue) value; update.setChildCount(castedValue.getVariableCount()); update.done(); } } catch (org.eclipse.debug.core.DebugException e) { e.printStackTrace(); } } public void update(org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate[] updates) { try { org.eclipse.debug.core.model.IValue value = variable.getValue(); org.sintef.thingml.resource.thingml.debug.ThingmlDebugValue castedValue = (org.sintef.thingml.resource.thingml.debug.ThingmlDebugValue) value; for (org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate update : updates) { int offset = update.getOffset(); int length = update.getLength(); for (int i = offset; i < offset + length; i++) { org.eclipse.debug.core.model.IVariable variable = castedValue.getChild(i); update.setChild(variable, i); } update.done(); } } catch (org.eclipse.debug.core.DebugException e) { e.printStackTrace(); } } public void update(org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate[] updates) { for (org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate update : updates) { try { update.setHasChilren(variable.getValue().hasVariables()); update.done(); } catch (org.eclipse.debug.core.DebugException e) { e.printStackTrace(); } } } }; } return null; } @SuppressWarnings("rawtypes") public Class[] getAdapterList() { return new Class[] {org.eclipse.debug.ui.actions.IToggleBreakpointsTarget.class}; } }