-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle new iOS DEsktop and Taskbar classes
- Loading branch information
1 parent
1eea442
commit 1bb05cc
Showing
2 changed files
with
163 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ain/java/org/openforis/collect/earth/app/desktop/MacOpenFilesInvocationHandlerNewIos.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.openforis.collect.earth.app.desktop; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Use reflection to be able to add the code specific to Mac OS X without generating compilation errors | ||
* This class generates a Proxy so that an Interface method can be invoked. Sort of implementing an Interface using reflection | ||
* @see <a href="https://blogs.oracle.com/poonam/entry/how_to_implement_an_interface">How to implement an interface using Reflection</a> | ||
* @author Alfonso Sanchez-Paus Diaz | ||
* | ||
*/ | ||
public class MacOpenFilesInvocationHandlerNewIos implements java.lang.reflect.InvocationHandler { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(MacOpenFilesInvocationHandlerNewIos.class); | ||
|
||
public MacOpenFilesInvocationHandlerNewIos() { | ||
super(); | ||
} | ||
|
||
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable | ||
|
||
{ | ||
|
||
Object result = null; | ||
|
||
try { | ||
|
||
// if the method name equals some method's name then call your method | ||
if ( m!= null && m.getName().equals("openFiles") && args !=null && args.length>0) { | ||
openFilesImplmentation(args[0]); | ||
} | ||
|
||
} catch (Exception e) { | ||
logger.error(" Error while interpreting invocation " , e ); | ||
} finally { | ||
logger.info("end method {}", m!=null?m.getName():"Unknown method"); | ||
} | ||
|
||
return result; | ||
|
||
} | ||
|
||
private void openFilesImplmentation(Object openFilesEventObject) throws Exception { | ||
Class openFilesEventClass = Class.forName("java.awt.dektop.OpenFilesEvent"); | ||
Method getFilesMethod = openFilesEventClass.getMethod("getFiles"); | ||
|
||
List<File> files = (List<File>) getFilesMethod.invoke( openFilesEventClass.cast( openFilesEventObject ) ); | ||
|
||
for (File file : files ){ | ||
try { | ||
EarthApp.openProjectFileInRunningCollectEarth(file.getAbsolutePath()); | ||
} catch (IOException e1) { | ||
logger.error("Error opening CEP file " + e1); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|