package jetbrains.mps.ide.httpsupport.nodeaccess.plugin; /*Generated by MPS */ import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.project.Project; import org.jetbrains.mps.openapi.model.SNodeReference; import jetbrains.mps.baseLanguage.closures.runtime.Wrappers; import org.jetbrains.mps.openapi.module.SRepository; import jetbrains.mps.openapi.navigation.NavigationSupport; import jetbrains.mps.project.MPSProject; import com.intellij.ide.impl.ProjectUtil; import com.intellij.openapi.application.ApplicationManager; import javax.swing.JComponent; import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.MessageType; import com.intellij.ui.awt.RelativePoint; import com.intellij.openapi.ui.popup.Balloon; public class HandlerUtil { public static final String SOURCE_GEN = "source_gen/"; public static final String HEADER = "<b>HTTP Support Plugin</b>\n"; public static final String HEADER_RESPONCE = "<b>MPS - HTTP Support Plugin</b><br>"; public static final String NO_PROJECT_IS_AVAILABLE = "An incoming request can not be handled properly since no project is available"; public static final int POPUP_TIME = 10000; public static final byte[] SUCCESS_STREAM = new byte[]{(byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x02, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x80, (byte) 0xFF, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x02, (byte) 0x44, (byte) 0x01, (byte) 0x00, (byte) 0x3B}; public static final byte[] FAILURE_STREAM = new byte[]{(byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x80, (byte) 0xFF, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x02, (byte) 0x44, (byte) 0x01, (byte) 0x00, (byte) 0x3B}; public static SNode openNode(final Project project, final SNodeReference nodeReference) { if (nodeReference == null) { return null; } final Wrappers._T<SNode> resolvedNode = new Wrappers._T<SNode>(); final SRepository repository = project.getRepository(); repository.getModelAccess().runWriteAction(new Runnable() { public void run() { resolvedNode.value = nodeReference.resolve(repository); } }); if (resolvedNode.value != null) { repository.getModelAccess().runWriteInEDT(new Runnable() { public void run() { NavigationSupport.getInstance().openNode(project, resolvedNode.value, true, true); requestFocus(project); } }); } return resolvedNode.value; } public static void requestFocus(Project project) { if (project instanceof MPSProject) { ProjectUtil.focusProjectWindow(((MPSProject) project).getProject(), true); } } public static String getNodeNotFoundText(final SNodeReference ref) { return "Can not find node <i>" + ref + "</i>\nMaybe it has been deleted?"; } public static void showNoProjectIsAvailablePopup() { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { JComponent component = (as_qa1yjq_a0a0a0a0a0a0a0a32(WindowManager.getInstance().findVisibleFrame(), IdeFrame.class)).getComponent(); createPopupAndShow(HEADER + NO_PROJECT_IS_AVAILABLE, component); } }); } public static void showNodeNotFoundPopup(final Project project, final SNodeReference ref) { final MPSProject mpsProject = as_qa1yjq_a0a0a52(project, MPSProject.class); final com.intellij.openapi.project.Project ideaProject = mpsProject.getProject(); project.getModelAccess().runReadInEDT(new Runnable() { public void run() { JComponent component = WindowManager.getInstance().getStatusBar(ideaProject).getComponent(); createPopupAndShow(HEADER + getNodeNotFoundText(ref), component); } }); } private static void createPopupAndShow(String text, JComponent component) { JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text, MessageType.WARNING, null).setFadeoutTime(POPUP_TIME).createBalloon().show(RelativePoint.getSouthWestOf(component), Balloon.Position.above); } private static <T> T as_qa1yjq_a0a0a0a0a0a0a0a32(Object o, Class<T> type) { return (type.isInstance(o) ? (T) o : null); } private static <T> T as_qa1yjq_a0a0a52(Object o, Class<T> type) { return (type.isInstance(o) ? (T) o : null); } }