Skip to content

Instantly share code, notes, and snippets.

View suxiaogang's full-sized avatar
🙄
busy writing bugs

Sam Su suxiaogang

🙄
busy writing bugs
  • NULL
  • UTM Zone 49
View GitHub Profile
/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* www.nanotux.com
*
* Modifications by Chris Van Patten
* http://www.vanpattenmedia.com
* Version 1.5
**/
@suxiaogang
suxiaogang / RenameIResource.java
Last active December 15, 2015 15:39
IResource rename in plugin development
protected boolean renameProject(IProject localProject, String newProjectName) {
RenameResourceProcessor renameProcessor = new RenameResourceProcessor(localProject);
renameProcessor.setNewResourceName(newProjectName);
CheckConditionsOperation condictionOperation = new CheckConditionsOperation(new RenameRefactoring(renameProcessor),
CheckConditionsOperation.FINAL_CONDITIONS);
CreateChangeOperation operation = new CreateChangeOperation(condictionOperation,
RefactoringCore.getConditionCheckingFailedSeverity());
PerformChangeOperation performChangeOperation = new PerformChangeOperation(operation);
@suxiaogang
suxiaogang / getCurrentProject.java
Last active December 15, 2015 15:39
getCurrentProject in plugin dev
public static IProject getCurrentProject(){
ISelectionService selectionService =
Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
IProject project = null;
if(selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
@suxiaogang
suxiaogang / Convert.java
Last active December 15, 2015 16:29
File <-> IFile
//File > IFile:
IContainer[] findContainersForLocationURI = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(
file.toURI());
IFile[] findFilesForLocationURI = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(filefile.toURI());
//IFile > File:
IProject fsProject = ResourceModelUtils.getProject(project);
@suxiaogang
suxiaogang / ZipUtils.java
Last active December 15, 2015 16:38
Zip unpack in Java
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ZipUtils {
private static final int BUFFER_SIZE = 4096;
public static String replaceLast(String string, String toReplace,
String replacement) {
int pos = string.lastIndexOf(toReplace);
if (pos > -1) {
return string.substring(0, pos)
+ replacement
+ string.substring(pos + toReplace.length(),
string.length());
} else {
return string;
@suxiaogang
suxiaogang / DisableControl.java
Last active December 18, 2015 00:19
Disable a control in SWT
public void switchDisableOfControl(Control control,boolean flag){
if (control instanceof Composite) {
Composite comp = (Composite) control;
for (Control c : comp.getChildren())
switchDisableOfControl(c, flag);
} else {
control.setEnabled(flag);
//text
if(control instanceof Text){
((Text) control).setText("");
@suxiaogang
suxiaogang / SetNamespaceInJDom.java
Created June 5, 2013 08:08
Set Namespace In JDom
public void write(Writer writer) throws Exception {
Element rootElement = new Element("ABC");
namespace = Namespace.getNamespace("","http://abc.com/abc_1_0_0");
rootElement.setNamespace(namespace);
rootElement.addNamespaceDeclaration(namespace);
Namespace ns = Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
rootElement.addNamespaceDeclaration(ns);
rootElement.setAttribute("schemaLocation", "http://abc.com/abc.xsd", ns);
this.writeDomain(rootElement);
Document document = new Document(rootElement);
@suxiaogang
suxiaogang / ProgressMonitorDialog.java
Last active December 19, 2015 08:29
ProgressMonitorDialog.java
ProgressMonitorDialog progress = new ProgressMonitorDialog(null);
try {
progress.run(false, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
monitor.beginTask("WORK NAME", IProgressMonitor.UNKNOWN);
try {
//do something
} catch (Exception e) {
e.printStackTrace();
@suxiaogang
suxiaogang / gist:5949330
Created July 8, 2013 14:31
Help JavaScript
javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferencePage)")