.//=====================================================================
.//
.// File:      quick_fixes.arc
.//
.// (c) Copyright 2015 by One Fact Inc. All rights reserved.
.//
.//=====================================================================
.// 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.
.//=====================================================================
.//
.include "arc/cme_names.inc"
.include "../MC-Java/arch_utils.inc"
.assign path = "org/xtuml/bp/core/common"
.assign rel_path = "src/${path}"
.//
package org.xtuml.bp.core.common;
//======================================================================
//
// File: BPQuickFix.java
//
// WARNING:      Do not edit this generated file
// Generated by: ${info.arch_file_name}
//
// (c) Copyright 2015 by One Fact Inc.  All rights reserved.
//
//======================================================================
import java.util.ArrayList;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IMarkerResolution;

import org.xtuml.bp.core.CorePlugin;
import org.xtuml.bp.core.ui.actions.*;

public class BPQuickFix implements IMarkerResolution {
    String message = null;
    IResource path = null;
	public BPQuickFix(String string, IResource iResource) {
		message = string;
		path = iResource;
	}

	@Override
	public String getLabel() {
		return "Click Finish to open the Chooser and locate a replacement element.";
	}

	@Override
	public void run(IMarker marker) {
		ArrayList<NonRootModelElement> list = new ArrayList<NonRootModelElement>();
		try {
			String id = (String)marker.getAttribute(IntegrityChecker.ID_TYPE);
			String type = (String)marker.getAttribute(IntegrityChecker.TYPE_TYPE);
			Class<?> clazz = Class.forName(type.split(" ")[1]);
			Path path = new Path((String)marker.getAttribute(IntegrityChecker.PATH_TYPE));
			PersistableModelComponent comp = PersistenceManager.findOrCreateComponent(path);
			comp.loadComponentAndChildren(new NullProgressMonitor());
			NonRootModelElement rootElem = comp.getRootModelElement();
			NonRootModelElement element = (NonRootModelElement) rootElem.getModelRoot().getInstanceList(clazz).get(id);
			if (element != null) {
			  list.add(element);
			  StructuredSelection sel = new StructuredSelection(list);
.select many menu_entries from instances of CME
.for each cme in menu_entries
  .if(cme.UsesSelectionDialog)
    .invoke result = get_action_class_name(cme)
    .assign an = "${result.body}"
    .invoke fn = get_func_name(cme)
    .select one class related by cme->O_OBJ[R2000]
    .invoke cn = get_class_name(class)
			  if (clazz.getSimpleName().equals("${cn.body}")) {
                ${an}.${fn.body}(sel);
			  }
  .end if
.end for
			}
		} catch (CoreException e) {
            CorePlugin.logError("Core Exception fixing dangling reference:", e);
        } catch (ClassNotFoundException e) {
        	CorePlugin.logError("Class not found fixing dangling reference:", e);
		}
	}
}
.emit to file "${rel_path}/BPQuickFix.java"
