?? action.java
字號:
package org.xicabin.radcake.core.handlers;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.ide.IDE;
import org.xicabin.radcake.core.CakePlugin;
import org.xicabin.radcake.core.preferences.PreferenceConstants;
import org.xicabin.radcake.core.util.CakeConvention;
/**
* Action for user event
*
* @author Darcy Young
*/
public abstract class Action {
public static void open(IWorkbenchPage page, IFile file) {
open(page, file, "");
}
public static void open(IWorkbenchPage page, IFile file, String text) {
IFile destFile = null;
// M -> C -> V
if (CakeConvention.looksLikeModel(file)) {
destFile = CakeConvention.getControllerFromModel(file);
} else if (CakeConvention.looksLikeView(file)) {
destFile = CakeConvention.getModelFromView(file);
} else if (CakeConvention.looksLikeController(file)) {
if (text == null || text.length() == 0) {
destFile = CakeConvention.getModelFromController(file);
} else {
destFile = CakeConvention.getViewFromAction(file, text);
}
}
try {
if (destFile != null && destFile.exists()) {
IDE.openEditor(page, destFile);
}
} catch (CoreException e) {
String clazz = destFile.getName();
System.err.println("OpenCakeFile can not open file: " + clazz);
e.printStackTrace();
}
}
public static void openModel(IWorkbenchPage page, IFile file) {
if (CakeConvention.looksLikeModel(file))
return;
IFile destFile = null;
if (CakeConvention.looksLikeController(file)) {
destFile = CakeConvention.getModelFromController(file);
} else if (CakeConvention.looksLikeView(file)) {
destFile = CakeConvention.getModelFromView(file);
}
try {
if (destFile != null && destFile.exists()) {
IDE.openEditor(page, destFile);
}
} catch (CoreException e) {
String clazz = destFile.getName();
System.err.println("OpenModelFile can not open file: " + clazz);
e.printStackTrace();
}
}
public static void openController(IWorkbenchPage page, IFile file) {
if (CakeConvention.looksLikeController(file))
return;
IFile destFile = null;
if (CakeConvention.looksLikeModel(file)) {
destFile = CakeConvention.getControllerFromModel(file);
} else if (CakeConvention.looksLikeView(file)) {
destFile = CakeConvention.getControllerFromView(file);
}
try {
if (destFile != null && destFile.exists()) {
IDE.openEditor(page, destFile);
}
} catch (CoreException e) {
String clazz = destFile.getName();
System.err
.println("OpenControllerFile can not open file: " + clazz);
e.printStackTrace();
}
}
public static void openView(IWorkbenchPage page, IFile file, String text) {
if (CakeConvention.looksLikeView(file))
return;
IFile destFile = null;
if (CakeConvention.looksLikeController(file)) {
destFile = CakeConvention.getViewFromAction(file, text);
if (destFile != null && !destFile.exists() && text != null
&& text.length() != 0) {
boolean prompt = CakePlugin.getInstance().getPreferenceStore()
.getBoolean(
PreferenceConstants.CREATE_MISSING_VIEW_PROMPT);
if (prompt) {
boolean createMissingView = MessageDialog.openConfirm(page
.getWorkbenchWindow().getShell(),
"Create missing view", "View " + destFile.getName()
+ " can not be found, create it ?");
if (createMissingView) {
try {
InputStream stream = new ByteArrayInputStream(
new byte[0]);
destFile.create(stream, true, null);
} catch (Exception e) {
System.err
.println("OpenViewFile can not create file: "
+ destFile.getName());
e.printStackTrace();
}
}
}
}
}
try {
if (destFile != null && destFile.exists()) {
IDE.openEditor(page, destFile);
}
} catch (CoreException e) {
String clazz = destFile.getName();
System.err.println("OpenViewFile can not open file: " + clazz);
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -